美文网首页
button换左右的图片和文字

button换左右的图片和文字

作者: 静守幸福 | 来源:发表于2018-01-08 21:30 被阅读36次

    This property is used only for positioning the image during layout

    其实titleEdgeInsets属性和 imageEdgeInsets属性只是在画这个button出来的时候用来调整image和label位置的属性,并不影响button本身的大小。

    它们只是image和button相较于原来位置的偏移量,那什么是原来的位置呢?就是没有设置edgeInset时候的位置了。

    如果要image在右边,label在左边,那image的左边相对于button的左边右移了labelWidth的距离,image的右边相对于label的左边右移了labelWidth的距离

    所以,self.oneButton.imageEdgeInsets = UIEdgeInsetsMake(0, labelWidth, 0, -labelWidth);为什么是负值呢?因为这是contentInset,是偏移量,不是距离

    同样的,label的右边相对于button的右边左移了imageWith的距离,label的左边相对于image的右边左移了imageWith的距离

    所以self.oneButton.titleEdgeInsets = UIEdgeInsetsMake(0, -imageWith, 0, imageWith);

    这样就完成image在右边,label在左边的效果了。

    相关文章

      网友评论

          本文标题:button换左右的图片和文字

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