直接上代码:
UITextView *textView = [[UITextView alloc]initWithFrame:CGRectMake(100, 100, 100, 80)];
[self.view addSubview:textView];
UILabel *lab = [[UILabel alloc]init];
lab.textColor = [UIColor redColor];
lab.numberOfLines= 0;
lab.text = @"我就瞅瞅能不能放下,我就瞅瞅能不能放下,我就瞅瞅能不能放下,我就瞅瞅能不能放下,我就瞅瞅能不能放下";
lab.font = [UIFont fontWithName:KPingFangSCMedium size:23];
lab.textAlignment = NSTextAlignmentCenter;
[textView addSubview:lab];
//右侧的约束并未生效
// [lab mas_makeConstraints:^(MASConstraintMaker *make) {
// make.leading.trailing.top.bottom.equalTo(textView);
// }];
[lab mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.top.bottom.equalTo(textView);
make.trailing.equalTo(self.view).offset(-ScreenWidth+200);
}];
这里是根据父控件进行约束,也可以设置宽度
网友评论