对于上下移动而言,取决于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.