美文网首页
UIButton中setTitleEdgeInsets和setI

UIButton中setTitleEdgeInsets和setI

作者: 萧哒哒 | 来源:发表于2020-09-10 16:20 被阅读0次

    button同时设置图片和文字,如果图片不超过button大小时会这样显示,图片在前+文字在后。

    实例

    需要改变为文字在前,图片在后,需要相对于现在这个位置做左右调整,上下无需调整。

    图片向右移动文字的宽度,即图片左边加上文字宽度,右边减去文字宽度,

    文字向左移动图片宽度,即文字左边减去图片宽度,右边加上图片宽度。

     //在使用一次titleLabel和imageView后才能正确获取titleSize

    button.titleLabel.backgroundColor = button.backgroundColor;

    button.imageView.backgroundColor = button.backgroundColor;

        CGSize titleSize = self.addressBtn.titleLabel.bounds.size;

        CGSize imageSize = self.addressBtn.imageView.bounds.size;

        CGFloatinterval =0.0;(间距)

        self.addressBtn.imageEdgeInsets=UIEdgeInsetsMake(0,titleSize.width+ interval,0, -(titleSize.width+ interval));

        self.addressBtn.titleEdgeInsets=UIEdgeInsetsMake(0, -(imageSize.width+ interval),0, imageSize.width+ interval);

    相关文章

      网友评论

          本文标题:UIButton中setTitleEdgeInsets和setI

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