简体   繁体   English

如何为按钮设置UIEdgeinset的值

[英]how to set the values for UIEdgeinset for button

I wanted to increase the button touch area without without actually increasing its original size. 我想在不实际增加其原始尺寸的情况下增加按钮的触摸面积。

When it comes to insets there are so many in Button and there is no clear documentation I could find on the differences 当涉及到插图时,Button中有很多东西,没有清晰的文档可以找到它们之间的区别

  • Content Insets 内容插图

  • Title Insets 标题插图

  • Image Insets 图像插图

So later on I thought to try on content inset. 所以后来我想尝试内容插入。 According to other stack overflow answers settings negative value to all the co-ordiantes(left,top,right,bottom) will increase the touch area of button without actually increasing its width and height. 根据其他堆栈溢出答案,将所有协处理器(左,上,右,下)的负值设置为负数会增加按钮的触摸面积,而实际上并未增加其宽度和高度。

But interfacebuilder doesn't allow me to enter values on all. 但是interfacebuilder不允许我输入所有值。

for example if i enter -10 in left and I couldn't enter -10 in right and others like that. 例如,如果我在左侧输入-10,而我在右侧输入-10,而其他类似的输入。

I am very much confused on this can somebody help me unravel the complexity 我对此很困惑,有人可以帮助我解开复杂性

thanks 谢谢

Try something like this: 尝试这样的事情:

func setupButton(button: UIButton) {
    button.titleEdgeInsets = UIEdgeInsetsMake(top, left, bottom, right)
    button.imageEdgeInsets =  UIEdgeInsetsMake(top, left, bottom, right)
    button.contentEdgeInsets =  UIEdgeInsetsMake(top, left, bottom, right)
}

You can refer This link for more elaborated answer. 您可以参考此链接以获得更详尽的答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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