static CGSize _calculateStringSize(NSString *str, id font, CGSize *constrainSize)
{
NSArray *listItems = componentsSeparatedByString: @"\n"];
CGSize dim = CGSizeZero;
CGSize textRect = CGSizeZero;
textRect.width = constrainSize->width > 0 ? constrainSize->width
: 0x7fffffff;
textRect.height = constrainSize->height > 0 ? constrainSize->height
: 0x7fffffff;
for (NSString *s in listItems)
{
CGSize tmp = sizeWithFont:font constrainedToSize:textRect];
if (tmp.width > dim.width)
{
dim.width = tmp.width;
}
dim.height += tmp.height;
}
return dim;
}
这个方法是不是不对啊,我每次使用cclabel的时候,如果输入的字符 存在“\n”的话,设置demensions就不起作用了,修改成下面的就好了。不知道改的对不对,大家讨论下
static CGSize _calculateStringSize(NSString *str, id font, CGSize *constrainSize)
{
CGSize textRect = CGSizeZero;
textRect.width = constrainSize->width > 0 ? constrainSize->width
: 0x7fffffff;
textRect.height = constrainSize->height > 0 ? constrainSize->height
: 0x7fffffff;
CGSize tmp = sizeWithFont:font constrainedToSize:textRect];
return tmp;
}