详细使用:
UILabel *label = [[UILabelalloc] initWithFrame:CGRectMake(0, 0, 75, 40)]; //声明UIlbel并指定其位置和长宽
label.backgroundColor = [UIColorclearColor]; //设置label的背景色,这里设置为透明色。
label.font = [UIFont fontWithName:@"Helvetica-Bold" size:13]; //设置label的字体和字体大小。
label.transform = CGAffineTransformMakeRotation(0.1); //设置label的旋转角度
label.text = @“helloworld”; //设置label所显示的文本
label.textColor = [UIColorwhiteColor]; //设置文本的颜色
label.shadowColor = [UIColorcolorWithWhite:0.1falpha:0.8f]; //设置文本的阴影色彩和透明度。
label.shadowOffset = CGSizeMake(2.0f, 2.0f); //设置阴影的倾斜角度。
label.textAlignment = UITextAlignmentCenter; //设置文本在label中显示的位置,这里为居中。
//换行技巧:如下换行可实现多行显示,但要求label有足够的宽度。
label.lineBreakMode = UILineBreakModeWordWrap; //指定换行模式
label.numberOfLines = 2; // 指定label的行数
//lable的旋转
label.transform = CGAffineTransformMakeRotation(0.2); //设置label的旋转角度
[self.view addSubview:label]; //将label载入
//设置背景图片
UIColor *color = [UIColor colorWithPatternImage:[UIImage imageNamed:@"itemkaung2.png"]]; [myLabel setBackgroundColor:color];
//设置行间距
NSString *labelText = @"我是内容,我是内容,我是内容,我是内容,我是内容。"; NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:labelText]; NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; [paragraphStyle setLineSpacing:LINESPACE];//调整行间距 [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [labelText length])]; label.attributedText = attributedString; [contentView addSubview:label]; [label sizeToFit];
//自定义高度
只需要一个方法:sizetofit 这个方法就够用了 。
