美文网首页Swift编程swift
UIButton中image和title的位置处理

UIButton中image和title的位置处理

作者: 何以消摇 | 来源:发表于2018-11-03 18:16 被阅读1次

需求:

有图片和文字的按钮,大部分时候不满足UI设计,所以需要微调。

思路

UIButton 提供了 titleEdgeInsets 与 imageEdgeInsets 属性

问题

titleEdgeInsets、imageEdgeInsets怎么设置

解答

if 内容的高 + |top - bottom| > 按钮的高 {
    top - bottom 为内容下移的距离(负数上移)
} else { 

    // top 为内容的 y,bottom为内容的maxY 
    y = top
    height = bottom - top
}

它们是 UIEdgeInsets 类型
有 top、bottom、left、right四个属性分别表示 上、下、左、右边距。top 和 bottom 决定了 内容的 y 与 height,left 和 right 决定了 内容的 x 与 width。

附图

图片

相关文章

网友评论

    本文标题:UIButton中image和title的位置处理

    本文链接:https://www.haomeiwen.com/subject/tndcbftx.html