0

Possible Duplicate:
Simple way of using irregular shaped buttons

I found examples about creating a rect or round UIButton.

Is possible to create an UIButton with a particular shape (e.g. a heart, a star and so on)?

How?

Community
  • 1
  • 1
Sefran2
  • 3,480
  • 12
  • 70
  • 105

1 Answers1

0

The easiest way to accomplish that is using:

UIButton *myButton=[UIButton buttonWithType:UIButtonTypeCustom];
[myButton setFrame:CRectMake( 0, 0, imWidth, imHeight)];
[myButton setBackgroundImage:[UIImage imageNamed:@"shabadabada.png"] forState:UIControlStateNormal];

And that would get you a simple button ... though it is not actually shaped like a "shabadabada" (:P) it will be a squared button.

To do a truly custom shaped "button" you would have to implement from the UIView class:

-(void) drawRect:(CGRect)rect;

And you would have to draw your shape point by point, here's a simple guide on doing this.

And also respond to the following methods:

– touchesBegan:withEvent:
– touchesMoved:withEvent:
– touchesEnded:withEvent:
– touchesCancelled:withEvent:

Or just to:

– addGestureRecognizer:
BenMorel
  • 31,815
  • 47
  • 169
  • 296
El Developer
  • 3,300
  • 1
  • 19
  • 40