简体   繁体   English

如何以编程方式将约束添加到tableView单元格的默认textLabel和annexView

[英]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.

相关问题 如何以编程方式将约束添加到UITableViewCell的默认imageView和textLabel - How to add Constraints programmatically to default imageView and textLabel of UITableViewCell 如何更改默认表视图单元格textlabel中的X位置? - How to change X position in Default tableview cell textlabel? 如何在tableview单元格中调整textlabel的大小 - how to resize textlabel in a tableview cell 如何更改tableView单元格textLabel的宽度 - How to change the width of tableView cell textLabel 如何以编程方式在TableView单元格中添加多个UIImageView - How to add multiple UIImageView in a TableView Cell programmatically 如何在tableview单元ios swift中获取accessoryView框架的框架 - How to get frame of accessoryView frame in tableview cell ios swift 滚动tableview时,UITableviewcell cell.textlabel.text会重复吗?如何避免cell.textlabel.text重复? - UITableviewcell cell.textlabel.text repeats when scrolling the tableview? how to avoid the cell.textlabel.text repetation? 无法刷新tableView中的单元格textLabel - Cannot refresh cell textLabel in tableView 如何将多个 cell.textLabel.text 用于多个 tableview? - How to use multiple cell.textLabel.text for multiple tableview? 如何在Tableview单元格中更新TextLabel iOS Swift - How to update textLabel inside a tableview cell iOS Swift
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM