直接上代码:
UIImage *normal = [UIImageimageNamed:@"xxx"];
// iOS5之前的办法 左边和上边分别有多少需要保护(一般为宽高的一半)
normal = [normal stretchableImageWithLeftCapWidth:normal.size.width * 0.5topCapHeight:normal.size.height * 0.5];
iOS5后的办法 设置上下左右多少需要保护
normal = [normal resizableImageWithCapInsets:UIEdgeInsetsMake(<#CGFloat top#>,<#CGFloat left#>, <#CGFloat bottom#>, <#CGFloat right#>)];
//iOS6后的办法 设置上下左右多少需要保护及拉伸模式(平铺&直接拉伸)
normal = [normal resizableImageWithCapInsets:<#(UIEdgeInsets)#>resizingMode:<#(UIImageResizingMode)#>];