行数为一行:自适应宽度
self.titleLbl.font = [UIFont systemFontOfSize:14.0];
self.titleLbl.numberOfLines = 1;//
CGSize size = [self.titleLbl.text sizeWithAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont systemFontOfSize:14.0],NSFontAttributeName, nil]];
self.titleLbl.frame = CGRectMake(10, self.frame.size.height-size.height-4,
size.width, size.height);
text和attributeText的关系
设置attributeText时,不要再设置text,否则会attributeText的属性会影响text;
设置label旋转
- 方法一: 使用
transform属性
,但是整个view都会旋转.
self.titleLbl.transform = CGAffineTransformMakeRotation(0.2)
- 方法二: 使用
NSMutableAttributedString
, 设置NSObliquenessAttributeName
NSString *titleLblText = @"+240";
NSMutableAttributedString *titleAttrStr = [[NSMutableAttributedString alloc] initWithString:titleLblText];
[titleAttrStr addAttribute:NSObliquenessAttributeName value:@(0.5) range:NSMakeRange(0, titleLblText.length)];
self.titleLbl.attributedText = titleAttrStr;