将 UIButton 对齐到 UITableViewCell 的右侧

Posted

技术标签:

【中文标题】将 UIButton 对齐到 UITableViewCell 的右侧【英文标题】:Aligning UIButton to the right of UITableViewCell 【发布时间】:2015-06-30 11:16:26 【问题描述】:

我正在使用 Xcode 的界面构建器构建一个简单的 UITableView 和自定义 UITableViewCell 设计,其中 UILabel 应该对齐到左侧,UIButton(下面屏幕截图中的安装按钮)对齐向右。

无论我使用何种约束组合,我似乎都无法解决此布局问题。每次构建和运行时,安装按钮总是被强制向屏幕左侧。请查看下面的两个屏幕截图以更好地了解该问题。谢谢!

【问题讨论】:

yourbutton.titleLabel.textAlignment = UITextAlignmentRight; 请将 UITextAlignmentRight 改为 NSTextAlignmentRight 不是标签,但 UIButton 文本标题工作正常 【参考方案1】:
yourbutton.titleLabel.textAlignment = NSTextAlignmentRight;

【讨论】:

你在 tableviewcellforrowatindexpath 方法中有代码吗? 给我 Github 链接我检查并告诉你

以上是关于将 UIButton 对齐到 UITableViewCell 的右侧的主要内容,如果未能解决你的问题,请参考以下文章