如何使用可拉伸的图片自定义UIButton,类似9patch效果
2012-05-17 11:24
387 查看
在Interface Builder中,UIButton的backgroundImage不支持拉伸,准确的说是UIButton中的backgroundImage不能支持contentStretch属性,在IB中,不能单独对UIButton的backgroundImage设置contentStretch属性。这个属性可以在代码中设置,如下:
这个方法比android中的9patch方式要麻烦一些,但聊胜于无。
- (void)viewDidLoad { UIImage *buttonBackgroundImage = [UIImage imageNamed:@"green-button.png"]; UIImage *stretchedBackground = [buttonBackgroundImage stretchableImageWithLeftCapWidth:33 topCapHeight:0]; [sendButton setBackgroundImage:stretchedBackground forState:UIControlStateNormal]; }或者:
UIImage *backgroundImage = [[UIImage imageNamed:@"ImageBackground.png"] stretchableImageWithLeftCapWidth:10 topCapHeight:0]; [myButton setBackgroundImage:backgroundImage forState:UIControlStateNormal];
这个方法比android中的9patch方式要麻烦一些,但聊胜于无。
相关文章推荐
- 类似9patch效果的iOS图片拉伸
- 类似9patch效果的iOS图片拉伸
- 自定义ImageView实现类似微信朋友圈发图片点击出来阴影效果;同时使用Picasso加载网络图片
- 博主教你制作类似9patch效果的iOS图片拉伸
- 博主教你制作类似9patch效果的iOS图片拉伸
- Android中使用自定义的view实现圆形图片的效果
- geoserver如何配置样式,使图层使用自定义图片?
- Android中如何使用ViewPager实现类似laucher左右拖动效果
- android progressbar 使用自定义图片时的左右两端圆角效果实现
- Android提高篇之自定义dialog实现processDialog“正在加载”效果、使用Animation实现图片旋转
- Android中如何使用ViewPager实现类似laucher左右拖动效果 3ff8
- Android提高篇之自定义dialog实现processDialog“正在加载”效果、使用Animation实现图片旋转
- Android中如何使用ViewPager实现类似laucher左右拖动效果
- Android 使用ViewPager实现类似gallery画廊的效果(画廊效果之ViewPager显示多个图片)
- iOS 实现类似安卓.9.png图片拉伸效果
- 如何使用Java代码给图片增加倒影效果
- [待解决]自定义头像时使用vue-cropper进行图片裁剪,得到的是base64格式的图片,如何对接file类型的api接口
- Android中如何使用ViewPager实现类似laucher左右拖动效果
- ajax实例:如何使用json+ajax的方法实现类似前端特效tab切换效果
- iOS—类似Android 9 patch效果图片拉伸