【发布时间】:2017-12-22 09:40:06
【问题描述】:
我有一个单元格,因为我想要默认行为,所以我使用以下方式 -
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}];
现在我遇到的问题是,文本如果小的话可以正常工作,但如果它很长,它会落后于开关......
现在我的问题是我如何避免这种情况并在我的 textLabel 和 accessoryView(UISwitch) 之间添加约束来解决这个问题,这两个都是默认的并且没有作为 subView 添加到单元格的 contentView 中??
提前致谢!!!请帮忙。
【问题讨论】:
-
最好有约束。
-
首选创建自定义xib单元
标签: ios objective-c uitableview autolayout