开发者

UI Button with Image Smaller than Touchable Area

I've not much response so am adding some more info.

My buttons are not rectangular, nor organised in a grid so I need a way of creating what looks like a button (and shows that it has been pressed visually, as per a standard UIButton) but where the touchable area is different to the image area.

I am using a transparent PNG and that element works fine. I've added the buttons in Interface Builder and am wondering if that is the problem.

However, if I change imageEdgeInsets, it distorts the image display, which is obviously not what I want.

Bizarrely, if I increase the dimemsions of the button, it doesn't change the image, but if I decrease them it does.

I have tried different combinations of mode (scale to fill etc), but to no avail.

I am aware that there is an image an开发者_Go百科d background image property, but in IB there is only one.

Essentially, I don't understand how the geometry works and the Apple documentation doesn't seem to help.

Surely, I can't be the only person to try to do this. Any help would be warmly welcomed.

Many thanks,

Chris.


Try setting the buttons setting to Aspect Fit. This will fill the button with your image so a smaller image than the button size would leave the space around the image.

Also set the button type to custom.

UI Button with Image Smaller than Touchable Area


In the end, I stumbled across Ole Begemann's Non-rectangular buttons class. It just does what I need - to be able to create buttons where the touchable area follows the visible element of a non rectangular image.

@Helium3 - thanks - that allowed me to use a larger touch area, bit not a smaller one.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜