Open ma125125t opened 5 years ago
示例代码如下
NSMutableAttributedString *hiddenTagText = [[NSMutableAttributedString alloc] initWithString:@"阿萨德"]; hiddenTagText.color = UIColor.blackColor; hiddenTagText.font = [UIFont systemFontOfSize:10]; NSLog(@"%f",hiddenTagText.size.width); YYTextContainer *c = [YYTextContainer containerWithSize:CGSizeMake(400, CGFLOAT_MAX) insets:UIEdgeInsetsZero]; YYTextLayout *_privateTagTextLayout = [YYTextLayout layoutWithContainer:c text:hiddenTagText]; YYLabel *_profileTag = [[YYLabel alloc] initWithFrame:CGRectMake(100, 100, 0, 30)]; _profileTag.backgroundColor = UIColor.yellowColor; // _profileTag.width = _privateTagTextLayout.textBoundingSize.width+30; _profileTag.textLayout = _privateTagTextLayout; [self.view addSubview:_profileTag];
[hiddenTagText setYy_alignment:NSTextAlignmentCenter];
示例代码如下