简体   繁体   中英

How to draw UIButton with shape as below?

I want to draw UIButton in following shape :

在此处输入图片说明

I have cut the image, so the edges are not straight. Please consider them straight. Also the bottom right corner is as shown. It is cut in quarter of circle.

I am not able to draw this shape for UIButton . How to do this?

[self.myButton setBackgroundImage:[UIImage imageNamed:@"myOddlyShapedImage"] forState:UIControlStateNormal];

I got the same problem, I found a different UIBUtton libraries and solved this

search for:

GB2ShapeCache

and implement if you don't find it I could upload it and I give you the link.

You only put the library in your UIBUtton and it will work

I hope it helps :)

Interesting question. I did a search and found two simple solutions that seem much simpler than the GB2. They override either hitTest:withEvent: or pointInside:withEvent: to take into account if the current pixel is transparent or not. So just take your image, set the lower right corner to transparent in a graphics editor, and use one of these classes.

http://iphonedevelopment.blogspot.com/2010/03/irregularly-shaped-uibuttons.html and http://oleb.net/blog/2009/10/obshapedbutton-non-rectangular-buttons-on-the-iphone/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM