UILabel+Addtions.m 997 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
//
//  UILabel+Addtions.m
//  RealEstateManagement
//
//  Created by Javen on 2017/1/8.
//  Copyright © 2017年 上海勾芒信息科技. All rights reserved.
//

#import "UILabel+Addtions.h"

@implementation UILabel (Addtions)

@end

@implementation UILabel (ContentSize)

- (CGSize)contentSize {
  NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  paragraphStyle.lineBreakMode = self.lineBreakMode;
  paragraphStyle.alignment = self.textAlignment;
  
  NSDictionary * attributes = @{NSFontAttributeName : self.font,
                                NSParagraphStyleAttributeName : paragraphStyle};
  
  CGSize contentSize = [self.text boundingRectWithSize:self.frame.size
                                               options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading)
                                            attributes:attributes
                                               context:nil].size;
  return contentSize;
}

@end