CGSize labelSize = [str sizeWithFont:[UIFont boldSystemFontOfSize:17.0f]
constrainedToSize:CGSizeMake(280, 100)
lineBreakMode:UILineBreakModeCharacterWrap]; // str是要显示的字符串
UILabel *patternLabel = [[UILabel alloc] initWithFrame:CGRectMake(35, 157, labelSize.width, labelSize.height)];
patternLabel.text = str;
patternLabel.backgroundColor = [UIColor clearColor];
patternLabel.font = [UIFont boldSystemFontOfSize:17.0f];
patternLabel.numberOfLines = 0; // 不可少Label属性之一
patternLabel.lineBreakMode = UILineBreakModeCharacterWrap; // 不可少Label属性之二
[self.view addSubview:patternLabel];
[patternLabel release];
转自:http://blog.csdn.net/xiaobo16/article/details/8227325
文字凹陷效果
UILabel *label= [[UILabelalloc]initWithFrame:CGRectMake(10,10, 300, 100)];
label.text = @"文字凹陷效果";
label.shadowColor= [UIColor colorWithRed:0.855green:0.863 blue:0.882alpha:1.0];
label.textColor= [UIColor colorWithRed:0.298green:0.337 blue:0.424alpha:1.0];
label.backgroundColor =[UIColor cyanColor];
[mainView addSubview:label];
[label release];
文字阴影效果
UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(10, 10,300, 100)];
label.text = @"文字阴影效果";
label.textColor= [UIColor colorWithRed:0.4green:0.6 blue:0.1alpha:1.0];
label.textAlignment=UITextAlignmentCenter;
label.font = [UIFont fontWithName:[[UIFont familyNames] objectAtIndex:2]size:35];
label.adjustsFontSizeToFitWidth = YES;
label.numberOfLines = 0;
label.tag = 0;
label6.backgroundColor =[UIColor cyanColor];
label.shadowColor = [UIColor yellowColor];
label.shadowOffset = CGSizeMake(3, 3);
[mainView addSubview:label];
[label release];
label中文字跑马灯效果
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 300, 100)];
label.text = @"噜啦啦噜啦啦噜啦噜啦噜,噜啦噜啦噜啦噜啦噜啦噜~~~";
[self.view addSubview:label];
CGRect frame = label7.frame;
frame.origin.x = -180;
label.frame = frame;
[UIView beginAnimations:@"testAnimation" context:NULL];
[UIView setAnimationDuration:8.8f];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDelegate:self];
[UIViewsetAnimationRepeatAutoreverses:NO];
[UIView setAnimationRepeatCount:999999];
frame = label.frame;
frame.origin.x = 350;
label.frame = frame;
[ UIView commitAnimations ];