object-c sizeWithFont

 ********************************    IOS6 获取字符串size    ********************************

单行字符串:  CGSize size_width = [str_new sizeWithFont:[UIFont systemFontOfSize:20]];

多行字符串: CGSize labelSize = [self.textLabel.text sizeWithFont:[UIFont systemFontOfSize:14.0f]

                                       constrainedToSize:CGSizeMake(226.0f, MAXFLOAT)

                                           lineBreakMode:0];

 

********************************    IOS7 获取字符串size     ********************************

单行字符串: CGSize size_width = [str_new sizeWithAttributes: @{NSFontAttributeName:[UIFont systemFontOfSize:20]}];

多行字符串:CGSize labelSize = [self.textLabel.text boundingRectWithSize:CGSizeMake(226, MAXFLOAT) options:NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]} context:nil].size;

 

备注:

NSStringDrawingOptions参数

 

 

posted on 2015-02-03 14:42  马大哈哈  阅读(227)  评论(0)    收藏  举报

导航