计算文本大小

来源:互联网 发布:禁止xp系统安装软件 编辑:程序博客网 时间:2024/06/06 17:55

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);


// 汉字转拼音

NSMutableString *ms = [[NSMutableString alloc] initWithString:@"我是中国人"];
if (CFStringTransform((__bridge CFMutableStringRef)ms, 0, kCFStringTransformMandarinLatin, NO)) {
    NSLog(@"Pingying: %@", ms); // wǒ shì zhōng guó rén
}
if (CFStringTransform((__bridge CFMutableStringRef)ms, 0, kCFStringTransformStripDiacritics, NO)) {
    NSLog(@"Pingying: %@", ms); // wo shi zhong guo ren
}

0 0
原创粉丝点击