forkingdog / forkingdog/UITableView-FDTemplateLayoutCell
在Cell中设置Label距离ContentView左右的间距,出现约束冲突
- Dominant language
- Objective-C
- Stars
- 9.9k
- Forks
- 2k
- PR merge metrics
- No merged PRs in 30d
Description
使用Masonry设置约束,想让label距左右边距为10,代码如下:
```
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
UILabel *infosLabel = [[UILabel alloc] init];
[infosLabel setFont:[UIFont systemFontOfSize:14.f]];
[infosLabel setTextColor:kDefaultFontGrayColor];
[infosLabel setNumberOfLines:0];
[self.contentView addSubview:infosLabel];
_infosLabel = infosLabel;
[infosLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.bottom.equalTo(self.contentView);
make.left.equalTo(self.contentView).offset(10);
make.right.equalTo(self.contentView).offset(-10);
}];
}
return self;
}
```
会出现以下约束冲突:
```
(
"",
"",
""
)
```
是因为设置约束的时候,ContentView的宽度为0 ?
我看Demo里面,有这么一句设置ContentView的尺寸 加进去也没有用
```
// Fix the bug in iOS7 - initial constraints warning
self.contentView.bounds = [UIScreen mainScreen].bounds;
```
用storyboard不会出现这样的冲突。是我约束设置有问题吗?
望指点,谢谢。
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.