0

i have to create Oval shaped Football ground like thisenter image description here

But i have no idea about which class/Object can do this in iPhone? and when user touch this ,he/she got the position of football.i did lot of googling,but not succeeded,Please Help!! i am trying this code in UIButton

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];


button.backgroundColor=[UIColor greenColor];
[button addTarget:self action:@selector(TappeMe) forControlEvents:UIControlEventTouchUpInside];

[button setTitle:@"" forState:UIControlStateNormal];

button.frame = CGRectMake(15.0, 10.0, 300.0, 400.0);

button.clipsToBounds = YES;

button.layer.cornerRadius = 130;
button.layer.borderColor=[UIColor redColor].CGColor;

button.layer.borderWidth=3.0f;

[self.view addSubview:button];

i got this Outputenter image description here

Thanks in Advance

Ankit Gupta
  • 958
  • 1
  • 6
  • 19
  • what framework are you using to create ground of that shape ?please post some code regarding some thing you had tried ? – NIKHIL Apr 27 '12 at 06:19
  • @NikhilBansal i have to create oval shaped UImageView or UIButton or UiVIew, Not Design.Beacuse User touch in this field,they get position in field something. – Ankit Gupta Apr 27 '12 at 06:23
  • My suggestion is to make this ground from your designer and tell him to make the corner color's alpha=0 or i can say tell him to not set the color of the portion whose color u r showing gray in this image.After that you just have to take an image and count the alpha on the selected pixel.if your selected pixel would have zero alpha then you should not perform your selector and if your selected pixel would have not zero alpha then perform your selector.Thats it!!!! – Nikhil Bansal Apr 27 '12 at 06:24
  • Let me tell you i have already use this thing,like i have to use an tabla image.you know very well tabla is always in circular shape.what i have done is got an tabla image from designer whose corner are like invisible.for example you are showing gray corners here in this image.if designer give you such image then only your oval shaped ground will be seen not an image which has gray corners and ground.are you getting my point? – Nikhil Bansal Apr 27 '12 at 06:29
  • @NSMutableArrayRetained i have posted code and Output, Please Help. – Ankit Gupta Apr 27 '12 at 06:45

2 Answers2

1

You need to draw it yourself using UIBezier paths -- that class has methods to create simple shapes like lines, ovals, rectangles, etc.

rdelmar
  • 103,982
  • 12
  • 207
  • 218
1

Simply use an UIImageView and add a UITapGestureRecognizer to the image view. See for example this UIGestureRecognizer tutorial.

DarkDust
  • 90,870
  • 19
  • 190
  • 224
  • DOes the gesture recognizer detect touches for places in the image with alpha set to 0? – Pochi Apr 27 '12 at 07:24
  • ISnt there a way to set a view as a mask so that touches in the image can be detected only in the inner circle? – Pochi Apr 27 '12 at 08:04
  • You can [check the alpha value of the image](http://stackoverflow.com/questions/8257099/how-to-detect-alpha-pixels-in-uiimage), for example in `hitTest:withEvent:` (if you want the touches to "go through") or in the tap gesture recognizer handler. – DarkDust Apr 27 '12 at 08:11
  • Cool, so the easiest way to do what he wants would be to make 2 images, a complete one, and the other with only where he wants touch enable and alpha with the rest, put them one over the other and do what you said right? I was curious thx for your help. – Pochi Apr 27 '12 at 08:31
  • Yes, that sounds like a sensible approach. Or maybe just one image with appropriate alpha values. – DarkDust Apr 27 '12 at 08:55