11

I have UIView that contain a pin image and a label, as we know UIView is rectangle so if I convert UIView to UIImage,UIImage is also rectangle, I want make UIImage like the a pin image because if user click a background, UIImage's event will be called too.. I want to convert UIView to UIImage without it's background, how can it be?

I use this method to change UIView to UIImage

-(UIImage *) ChangeViewToImage : (UIView *) view{

UIGraphicsBeginImageContext(view.bounds.size);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
  UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return img;
}

Hmm.. example like this, I have a rectangle as a UIView and a triangle as a shape in UIView. and then I want to make this UIView become a UIImage, but I just want the triangle without background, so the image just a triangle.. how can I do It?

Cœur
  • 37,241
  • 25
  • 195
  • 267
user4951
  • 32,206
  • 53
  • 172
  • 282

1 Answers1

8

A UIImage is always rectangular. What you can play with is the opacity in your views. If you make everything except your pin image transparent, it will seem as if you just have an image of the pin.

Use:

view.backgroundColor = [UIColor clearColor];

to make your view's background transparent.

adriaan
  • 1,574
  • 14
  • 33
  • Yea, I know.. the problem is, if we tap at background, the event will be called. can we do something with this problem? – user4951 Aug 02 '11 at 02:24
  • With adriaan answer I think you can disable user interaction on that view. – Emon Nov 28 '11 at 03:34