ios - 在左侧对齐 UIButton 的图像和 UILabel

标签 ios objective-c uibutton

我目前有:
enter image description here

使用这段代码:

button.semanticContentAttribute = UISemanticContentAttributeForceRightToLeft;
button.transform = CGAffineTransformMakeScale(-1.0, 1.0);
button.titleLabel.transform = CGAffineTransformMakeScale(-1.0, 1.0);
button.imageView.transform = CGAffineTransformMakeScale(-1.0, 1.0);

我想要实现的是:
enter image description here

图像和 UILabel 应该位于 UIButton 的左侧,而不是中间。

最佳答案

试试 contentHorizo​​ntalAlignment 属性。

objective-C

button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;

swift

button.contentHorizontalAlignment = .left

关于ios - 在左侧对齐 UIButton 的图像和 UILabel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50480177/

相关文章:

ios - 在 Objective-C 中使我的 UIViewController 全屏显示

ios - 激活 UITextField 时立即更改第一响应者

点击按钮时出现 iOS EXC_BAD_ACCESS 错误

iphone - UIView 下的 UIButton 不应该是可点击的

ios - iOS更新后搜索栏变形

iphone - 无法将文件复制到 Project

ios - 遇到405错误如何删除collectionview记录?

IOS:注销使用 CoreText 注册的字体

ios - 如何提供纵向和横向两种不同的 View ?

ios - 设置图像/背景图像时,UIButton 标题不会突出显示