直接上代碼:
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)#>];