OGeek|极客世界-中国程序员成长平台

标题: ios - UIControlStateHighlighted 的 UIButtonTypeSystem setBackgroundImage [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 16:01
标题: ios - UIControlStateHighlighted 的 UIButtonTypeSystem setBackgroundImage

在我的所有应用程序中,我都有带有 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/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4