关于titleEdgeInsets的使用
对于上下移动而言,取决于top和down的值,移动的距离为|top - down|/2,就是top减去down差的绝对值的一半,具体方向需要看这两个参数。左右的原理与上下一致。
A positive value shrinks, or insets, that edge—moving it closer to the center of the button. A negative value expands, or outsets, that edge,这句话是文档里的,意思就是如果参数值为正,那么相应方向将会向button的中心靠,负值,将会向外偏移。
现在只列举top与down来解释说明,分4种情况(参与运算的各参数一定要带符号)
1)top为正,down为正,移动的方向取决于值大的参数;如果top大于down,那么文字将向下移动,移动的距离为|top - down|/2,反之
2)top为正,down为负,移动的方向为向下;移动的距离为|top - down|/2
3)top为负,down为正,移动的方向为向上;移动的距离为|top - down|/2
4)top为负,down为负,移动的方向取决于绝对值大的参数;如果|top|大于|down|,那么文字将向上移动,移动的距离为|top - down|/2,反之
贴出文档中的描述
Discussion
Use this property to resize and reposition the effective drawing rectangle for the button title. You can specify a different value for each of the four insets (top, left, bottom, right). A positive value shrinks, or insets, that edge—moving it closer to the center of the button. A negative value expands, or outsets, that edge. Use the UIEdgeInsetsMake function to construct a value for this property. The default value is UIEdgeInsetsZero.
The insets you specify are applied to the title rectangle after that rectangle has been sized to fit the button’s text. Thus, positive inset values may actually clip the title text.
This property is used only for positioning the title during layout. The button does not use this property to determine intrinsicContentSize and sizeThatFits.
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步