美文网首页
iOS UIButton Image和Title自定义显示位置

iOS UIButton Image和Title自定义显示位置

作者: 你声音很好听 | 来源:发表于2017-06-20 16:44 被阅读0次

    UIButton设置了Image和Title之后,默认是并排居中显示的。

    这里的居中,是说image的宽度和title的宽度之和在button是居中的。并不是说图片和文字的中间就是按钮的中间,所以后面在计算偏移量的时候要注意这里。

    默认显示

    如果要改变位置,先设置UIButton的frame,然后调用button的两个方法:

    btn.imageEdgeInsets = UIEdgeInsetsMake(top, left, bottom, right)

    btn.titleEdgeInsets = UIEdgeInsetsMake(top, left, bottom, right)

    设置偏移之后

    相关文章

      网友评论

          本文标题:iOS UIButton Image和Title自定义显示位置

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