UIButton *button= [[UIButton alloc] initWithFrame:CGRectMake(0,0,70,70)];
button.buttonType = UIButtonTypeCustom;
UIImage *buttonImage = [UIImage imageNamed:@"image.png"];
UIImage *stretchableButtonImage = [buttonImage stretchableImageWithLeftCapWidth:12 topCapHeight:0];
[button setBackgroundImage:stretchableButtonImage forState:UIControlStateNormal];
如何让一个button 的 backgroundimage 等比例缩放 background imageview 并不完美
最新推荐文章于 2024-07-12 08:59:50 发布
本文介绍如何使用UIButton创建自定义按钮,并通过UIImage设置拉伸背景图片。首先创建UIButton实例,设置其类型为自定义,然后加载名为'image.png'的图片资源,将其转换为可拉伸图片,并最终设置为按钮背景。

758

被折叠的 条评论
为什么被折叠?



