[英]How to Add constraints programmatically to default textLabel and accessoryView of tableView cell
I have a cell and since i wanted the default behaviour i am using the following way - 我有一个单元格,并且由于我想要默认行为,所以我使用以下方式-
returnCell.textLabel.text = @"Some long text Some long text";
returnCell.textLabel.lineBreakMode = NSLineBreakByWordWrapping;
returnCell.textLabel.numberOfLines = 0;
UISwitch *toggleSwitch = [[UISwitch alloc] initWithFrame:CGRectZero];
returnCell.accessoryView = toggleSwitch;
[returnCell.contentView setTranslatesAutoresizingMaskIntoConstraints:NO];
[returnCell.textLabel setTranslatesAutoresizingMaskIntoConstraints:NO];
[returnCell addVisualConstraints:@"H:|[contentView]|"
forViews:@{@"contentView":returnCell.contentView}];
[returnCell addVisualConstraints:@"V:|[contentView]|"
forViews:@{@"contentView":returnCell.contentView}];
Now the problem that i have is, the text if small works fine but if it's long it goes behind the switch.... 现在我遇到的问题是,如果小文本可以正常工作,但如果很长,它将在开关后面...。
Now my question is how do i avoid this and add constraints to solve this problem between my textLabel and accessoryView(UISwitch) both of which are defalt and not added as subView to contentView of cell?? 现在我的问题是如何避免这种情况,并添加约束来解决我的textLabel和AccessoriesView(UISwitch)之间的问题,这两者都是默认的,而不是作为subView添加到单元的contentView中的?
Thanks in advance!!! 提前致谢!!! Please help.
请帮忙。
枚举contentView约束,直到找到带有textLabel的 尾随约束为止,并增加/减小它对第一个项的常数,直到它离开开关(accessoryView)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.