iOS学习集--网上转载功能实现参考小知识

经常遇到的需要对UILabel处理的几个问题

2016-04-15  本文已影响257人  SPIREJ
- (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];
}
CGFloat scale = [[UIScreen mainScreen] scale];
CGFloat width = scale > 0.0 ? 1.0 / scale : 1.0;
[self.layer setBorderWidth:width];
上一篇下一篇

猜你喜欢

热点阅读