- (CGSize)boundingRectWithSize:(CGSize)size text:(NSString *)text fount:(UIFont *)font
{
NSDictionary *attribute = @{NSFontAttributeName: font};
CGSize retSize = [text boundingRectWithSize:size options:NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin NSStringDrawingUsesFontLeading attributes:attribute context:nil].size;
return retSize;
}
-(CGSize)sizeWithString:(NSString *)text size:(CGSize)size font:(UIFont)font
{
CGSize size = [text sizeWithFont:font constrainedToSize:size lineBreakMode:NSLineBreakByWordWrapping];
return size;
}
+ (void)labelLineSpace:(UILabel *)label text:(NSString *)text Value:(CGFloat)value
{
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:text];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle setLineSpacing:value];
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [text length])];
label.attributedText = attributedString;
[label sizeToFit];
}
-
Label的边框宽度粗细不一致处理
- 如果设置了
label.layer.border.width
为某一值,在不能的屏幕上显示的效果可能完全不一样,比如我之前做项目是设置了 border.width = 0.6
,然后在6s上显示时粗细不一致,下面这方法可以解决这个问题。
CGFloat scale = [[UIScreen mainScreen] scale];
CGFloat width = scale > 0.0 ? 1.0 / scale : 1.0;
[self.layer setBorderWidth:width];
网友评论