计算文本大小

来源:互联网 发布:python中文分词代码 编辑:程序博客网 时间:2024/06/10 16:18
 NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:17], NSFontAttributeName, nil];
    
    CGRect rect = [str boundingRectWithSize:CGSizeMake(300, 100000) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    NSLog(@"rect = %@", NSStringFromCGRect(rect));
    
    label.frame = CGRectMake(0, 0, label.frame.size.width, rect.size.height);
    [label setText:str];
    [label setBackgroundColor:[UIColor yellowColor]];
    
    sc.contentSize = CGSizeMake(0, label.frame.size.height);
0 0