iphone - UIButton 选择颜色

标签 iphone objective-c cocoa-touch ios uibutton

<分区>

我正在绘制自定义 UIButton 并希望在突出显示时设置蓝色。我怎样才能做到这一点?

UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom];
[myButton setBackgroundImage:[[UIImage imageNamed:@"test.png"] stretchableImageWithLeftCapWidth:100 topCapHeight:0] forState:UIControlStateNormal];

最佳答案

您可以执行以下操作来为您的状态(正常/突出显示/选中)设置图像。你必须有图像。

[downButton setImage:[UIImage imageNamed:@"white.png"] forState:UIControlStateNormal];
[downButton setImage:[UIImage imageNamed:@"blue.png"] forState:UIControlStateHighlighted];

关于iphone - UIButton 选择颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6066776/

相关文章:

iphone - UIView 动画中的键值观察

ios - 如何将文本从 iOS Notes 应用程序导出到我的应用程序?

ios - 更改 QLPreviewController 中的导航栏颜色

ios - 为 iTunes 创建通用应用程序?

iphone - "Conforms to"在 Iphone 术语中代表什么?

ios - UITableView subview 滑动时显示 "extras"

ios - 开发过程中应该如何使用identifierForVendor?

ios - 作为 subview 添加的 UIButton 远离 UIView

objective-c - 使用IOS应用中的OAuth发布推文

objective-c - NSArray containsObject 没有像宣传的那样工作