给UILabel加入背景图片:
self.accountLabel = [[UILabel alloc]initWithFrame:CGRectMake(kXW(accountBtn), kY(accountBtn), 250, 32)];
self.accountLabel.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"qipao.png"]];
在iOS6.0中。UIImage提供了一个方法处理图片拉伸
- - (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets resizingMode:(UIImageResizingMode)resizingMode
- UIImageResizingModeStretch:拉伸模式,通过拉伸UIEdgeInsets指定的矩形区域来填充图片
- UIImageResizingModeTile:平铺模式。通过反复显示UIEdgeInsets指定的矩形区域来填充图片
- CGFloat top = 25; // 顶端盖高度
- CGFloat bottom = 25 ; // 底端盖高度
- CGFloat left = 10; // 左端盖宽度
- CGFloat right = 10; // 右端盖宽度
- UIEdgeInsets insets = UIEdgeInsetsMake(top, left, bottom, right);
- // 指定为拉伸模式,伸缩后又一次赋值
- image = [image resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch];