Gavin.han

致力于移动开发 技术改变生活

导航

ios UI控件之UILabel

Posted on 2012-10-22 11:46  gavin.han  阅读(251)  评论(0编辑  收藏  举报

 

上面的通过代码实现:

NSString *str = @"字符串大小字符串大小字符串大小字符串大小";
UIFont *font = [UIFont fontWithName:@"Arial" size:50.0f];
CGSize size = CGSizeMake(320, 2000);


UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
[label setNumberOfLines:0];


CGSize labelSize = [str sizeWithFont:font
constrainedToSize:size
lineBreakMode:UILineBreakModeWordWrap];


label.frame = CGRectMake(0, 0, labelSize.width, labelSize.height);
label.textColor = [UIColor blackColor];
label.font = font;
label.text = str;
[self.view addSubview:label];

下面的通过xib文件的拉控件实现