如何绘制形状如下的UIButton?

时间:2012-02-01 17:38:31

标签: iphone uibutton

我想在以下形状中绘制UIButton

enter image description here

我剪了图像,所以边缘不直。请直接考虑它们。右下角也如图所示。它被切成四分之一圆。

我无法为UIButton绘制此形状。这该怎么做?

3 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:1)

我遇到了同样的问题,我找到了不同的UIBUtton库并解决了这个问题

搜索:

GB2ShapeCache

并实施,如果你找不到它我可以上传它,我给你链接。

您只将库放在UIBUtton中,它可以正常工作

我希望它有所帮助:)

答案 2 :(得分:1)

有趣的问题。我做了一个搜索,发现了两个比GB2简单得多的简单解决方案。它们覆盖hitTest:withEvent:或pointInside:withEvent:以考虑当前像素是否透明。因此,只需拍摄图像,在图形编辑器中将右下角设置为透明,然后使用其中一个类。

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