ios - 如何设置按钮的 UIEdgeinsets 值

标签 ios uibutton autolayout uiedgeinsets imageedgeinsets

我想在不实际增加其原始大小的情况下增加按钮触摸区域。

当涉及到 insets 时,Button 中有很多,但我找不到关于差异的明确文档

  • 内容插入

  • 标题插入

  • 图像插图

所以后来我想试试内容插图。 根据其他堆栈溢出答案,为所有坐标(左,上,右,下)设置负值将增加按钮的触摸面积,而不会实际增加其宽度和高度。

但是 interfacebuilder 不允许我输入所有值。

例如,如果我在左边输入 -10,而我不能在右边输入 -10 等等。

我对此很困惑,谁能帮我解开这个复杂性

谢谢

最佳答案

尝试这样的事情:

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)
}

可以引用This link以获得更详尽的答案。

关于ios - 如何设置按钮的 UIEdgeinsets 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43275816/

相关文章:

ios - Swift 约束打破框架的宽度和高度

ios - 在 AVPlayerViewController 中点击播放按钮时执行操作

iphone - UIButton 渐变不起作用

ios - 哪个布局约束具有同等优先级?

ios - 为什么模态呈现 View Controller 会破坏我的 TableView 中的自动布局?

ios - 如何在 xcode 10.2.1/swift 4.2 中使用 'iterateEnum' 函数按照枚举列表中指定的特定顺序对数组中的字符串值进行排序

ios - 在不使用 coredata 的情况下按日期对 UITableView 进行分组

swift - 无法使用 UIButton.isHidden = false。那我怎样才能隐藏我的按钮呢?

ios - 在 iOS 中显示按钮而不是固定在 map 上

ios - 在 Swift 3 中以编程方式使用 ScrollView