IB通过单元格UITableViewCell添加UISWitch。以编程方式设置文本UILabel时,UISwitch会重叠。
如何才能避免这种情况?
发布于 2019-02-07 13:51:06
添加约束,表示它们之间的距离大于0
发布于 2014-07-15 14:42:19
获取UILabel中的文本大小,然后将UISwitch移动到新位置。
发布于 2019-08-13 19:53:05
如果你把开关放在你的UILabel的右边,你可以在你的代码中将它设置为单元格的附件视图:
let switch = UISwitch()
// Position the switch to the trailing edge of the cell
cell.accessoryView = switch
// Tell the text label to reduce text size if the switch gets in the way
cell.textLabel?.adjustsFontSizeToFitWidth = true 这样,你就不需要处理定位/自动布局了。我相信在界面生成器中也可以做到这一点--参见https://stackoverflow.com/a/45849911/1646862 (在这种情况下,请确保设置了标签的自动收缩属性)
https://stackoverflow.com/questions/24751397
复制相似问题