TYAttributedLabel icon indicating copy to clipboard operation
TYAttributedLabel copied to clipboard

设置富文本属性居中之后(kCTTextAlignmentCenter),请求到网络数据后设置TYTextStorage后显示的文字并不居中

Open CodeHry opened this issue 6 years ago • 8 comments

CodeHry avatar May 16 '18 06:05 CodeHry

同样碰到该问题,求解决方式

MrCaiWH avatar Jul 11 '18 03:07 MrCaiWH

补充一句,用Masonry布局的,确认是kCTTextAlignmentCenter,没用错,作者试一下吧

MrCaiWH avatar Jul 11 '18 03:07 MrCaiWH

自动布局设置preferredMaxLayoutWidth 这个属性了吗

12207480 avatar Jul 11 '18 08:07 12207480

  • (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); }];

MrCaiWH avatar Jul 17 '18 03:07 MrCaiWH

@12207480 是这么写的,有问题吗,朋友

MrCaiWH avatar Jul 17 '18 03:07 MrCaiWH

还是不行吗

12207480 avatar Jul 17 '18 07:07 12207480

@12207480 不行啊,朋友,我的布局代码是在layoutSubviews里写的

MrCaiWH avatar Jul 17 '18 07:07 MrCaiWH

@MrCaiWH 朋友,你是怎么解决的,我也遇到这个问题了

Datey avatar Aug 15 '21 07:08 Datey