计算字符串长度

来源:互联网 发布:mt4编程手册技术大全 编辑:程序博客网 时间:2024/05/20 04:29
#import "ViewController.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad {    [super viewDidLoad];        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 100, 300, 300)];    label.backgroundColor = [UIColor yellowColor];        //设置文本    label.text = @"Hello Linux Hello Linux Hello Linux Hello Linux Hello Linux ";    label.shadowColor = [UIColor redColor];    label.shadowOffset = CGSizeMake(5, -5);    [self.view addSubview:label];    label.lineBreakMode = NSLineBreakByCharWrapping;    label.numberOfLines = 0;        CGSize textSize = [label.text sizeWithFont:label.font constrainedToSize:CGSizeMake(300,10000) lineBreakMode:NSLineBreakByCharWrapping];        label.frame = CGRectMake(label.frame.origin.x, label.frame.origin.y, label.frame.size.width, textSize.height);    label.backgroundColor  = [UIColor redColor];            //字体库    NSArray *names = [UIFont familyNames];    for (NSString * name in names ) {        NSLog(@"%@",name);    }        label.font = [UIFont fontWithName:@"Didot" size:15];        NSLog(@"%f,%f",textSize.width,textSize.height);    // Do any additional setup after loading the view, typically from a nib.}- (void)didReceiveMemoryWarning {    [super didReceiveMemoryWarning];    // Dispose of any resources that can be recreated.}@end

1 0
原创粉丝点击