• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - UIControlStateHighlighted 的 UIButtonTypeSystem setBackgroundImage

[复制链接]
菜鸟教程小白 发表于 2022-12-12 16:01:22 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

在我的所有应用程序中,我都有带有 UIButtonTypeSystem 的 UIButton。 对于 ios7,我想以编程方式设置按钮外观。 对于正常状态,我需要带有蓝色边框颜色的白色背景 normal state button

对于突出显示的状态,我需要带有蓝色边框颜色的灰色背景 highlighted state button

(对于禁用状态,我需要带有灰色边框的白色背景)

我为每个状态创建了图像(包含背景和边框颜色)并使用 UIButton 的方法 setBackgroungImage:forState: 设置它们。 但是当按钮处于突出显示状态时,我得到了这个按钮样式 actual highlighted state button

我发现克服这种行为的唯一方法是将所有应用程序按钮类型从 UIButtonTypeSystem 更改为 UIButtonTypeCustom。意思是传递所有应用程序xib的

是否有其他方法可以在不更改所有应用程序按钮类型的情况下这样做

谢谢 投资返回率



Best Answer-推荐答案


您好,您可以像这样以编程方式设置按钮:

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self actionselector(aMethod
forControlEvents:UIControlEventTouchUpInside];
[button setTitle"Show View" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
[buuton setBackgroundColor:[UIColor colorWithRed255/255.0) green180/255.0) blue200/255.0) alpha:1]];
[view addSubview:button];

关于ios - UIControlStateHighlighted 的 UIButtonTypeSystem setBackgroundImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19653531/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap