UIButton 文字在左,icon在右的办法 您所在的位置:网站首页 uibutton文字居右 UIButton 文字在左,icon在右的办法

UIButton 文字在左,icon在右的办法

2024-06-17 23:52| 来源: 网络整理| 查看: 265

在开发中,经常会碰到按钮到文字和icon 时左时右的情况。默认的情况是icon左,文字右。如果想反过来,有下面几个办法。

方法一:

在 stackover 上看到的一个答案。通过写一个分类的办法。

button.transform = CGAffineTransformMakeScale(-1.0, 1.0); button.titleLabel.transform = CGAffineTransformMakeScale(-1.0, 1.0); button.imageView.transform = CGAffineTransformMakeScale(-1.0, 1.0); 方法二:

在xcode 中,在storyboard 中,也可以进行调整:

Attributes Tab > Ensure your Content Edge tab is selected for 'image':

vADsO.png

如果是代码的话,像这样:

button.imageEdgeInsets = UIEdgeInsetsMake(0, 100, 0, 0);



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有