项目开发中需要使用渐变字体标题,在UILabel显示渐变字体:
//set the title
UIColor *titleColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"iCtrl_Title_Bg"]];
NSString *title = NSLocalizedString(@"Setting", nil);
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 80, 44)];
titleLabel.textColor = titleColor;
titleLabel.text = title;
titleLabel.font = [UIFont boldSystemFontOfSize:20];
titleLabel.backgroundColor = [UIColor clearColor];
self.navigationItem.titleView = titleLabel;
[titleLabel release];
注意使用的图片必须是有渐变效果的。如:
效果如图: