在我所有的应用程序中,我都有带有 UIButtonTypeSystem 的 UIButton。 对于 ios7,我想以编程方式设置按钮外观。 对于正常状态,我需要带有蓝色边框颜色的白色背景
对于突出显示的状态,我需要带有蓝色边框颜色的灰色背景
(对于禁用状态,我需要带灰色边框的白色背景)
我为每个状态创建了图像(包含背景和边框颜色),并使用 UIButton 的方法 setBackgroungImage:forState: 设置它们。 但是当按钮处于高亮状态时,我得到了这个按钮样式
我发现克服此行为的唯一方法是将所有应用程序按钮类型从 UIButtonTypeSystem 更改为 UIButtonTypeCustom。意味着传递所有应用程序 xib 的
有没有另一种不改变所有应用程序按钮类型的方法
谢谢 投资返回率
最佳答案
您好,您可以像这样以编程方式设置按钮:
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:@selector(aMethod:)
forControlEvents:UIControlEventTouchUpInside];
[button setTitle:@"Show View" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
[buuton setBackgroundColor:[UIColor colorWithRed:(255/255.0) green:(180/255.0) blue:(200/255.0) alpha:1]];
[view addSubview:button];
关于ios - UIButtonTypeSystem 为 UIControlStateHighlighted 设置背景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19653531/