TYAttributedLabel
TYAttributedLabel copied to clipboard
设置富文本属性居中之后(kCTTextAlignmentCenter),请求到网络数据后设置TYTextStorage后显示的文字并不居中
同样碰到该问题,求解决方式
补充一句,用Masonry布局的,确认是kCTTextAlignmentCenter,没用错,作者试一下吧
自动布局设置preferredMaxLayoutWidth 这个属性了吗
-
(TYAttributedLabel *)protocolLabel { if (_protocolLabel == nil) { _protocolLabel = [[TYAttributedLabel alloc] init]; _protocolLabel.backgroundColor = [UIColor clearColor]; _protocolLabel.textAlignment = kCTTextAlignmentCenter; _protocolLabel.preferredMaxLayoutWidth = [UIScreen mainScreen].bounds.size.width; _protocolLabel.delegate = self; NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:@"绑定手机号即表明同意"]; [attributedString addAttributeTextColor:[UIColor colorWithRed:70.0f/255.0f green:76.0f/255.0f blue:86.0f/255.0f alpha:1.0f]]; [attributedString addAttributeFont:[UIFont systemFontOfSize:13.0f]]; [_protocolLabel appendTextAttributedString:attributedString]; [_protocolLabel appendLinkWithText:@"《用户协议》" linkFont:[UIFont systemFontOfSize:12.0f] linkColor:[UIColor colorWithRed:0.0f/255.0f green:179.0f/255.0f blue:160.0f/255.0f alpha:1.0f] underLineStyle:kCTUnderlineStyleNone linkData:nil]; } return _protocolLabel; }
[self.protocolLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.right.left.mas_equalTo(self); make.top.mas_equalTo(self.submitButton.mas_bottom).offset(15); }];
@12207480 是这么写的,有问题吗,朋友
还是不行吗
@12207480 不行啊,朋友,我的布局代码是在layoutSubviews里写的
@MrCaiWH 朋友,你是怎么解决的,我也遇到这个问题了