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,578
  • 13
  • 71
  • 106

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
  • 34,448
  • 50
  • 182
  • 322
El Developer
  • 3,345
  • 1
  • 21
  • 40