【问题标题】:Change UIButton background color更改 UIButton 背景颜色
【发布时间】:2011-10-08 21:02:09
【问题描述】:

有人可以帮助我如何将按钮背景从白色更改为不同的颜色。 我知道如何添加图像并使其成为自定义按钮,但我不知道如何将初始按钮颜色从白色更改为另一种颜色。 您的帮助将不胜感激。干杯。

【问题讨论】:

  • 我这里有点问题,颜色只有在点击按钮后才会出现,请任何建议。谢谢 。 -(IBAction) nom{ [[按钮层] setCornerRadius:8.0f]; [[按钮层] setMasksToBounds:YES]; [[按钮层] setBorderWidth:1.0f]; [按钮设置背景颜色:[UIColor redColor]]; }

标签: iphone objective-c xcode4


【解决方案1】:

我有类似的要求,不想在我的应用程序包中包含其他文件,所以我编写了两个类,它们从 RGBA 值生成按钮图像并将它们添加到 UIButton。

创建按钮图像的类:

使用按钮图像创建按钮的类:

如果将以上四个文件添加到项目中,您应该可以使用以下方法创建具有彩色背景的 UIButton:

UIButton * deleteButton = [BKButton redButton];
UIButton * selectButton = [BKButton lightGrayButton];
UIButton * customButton = [BKButton buttonWithRed:0.0 green:0.4 blue:0.37 alpha:1.0];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-02-22
    • 2021-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-29
    • 2011-12-30
    • 1970-01-01
    相关资源
    最近更新 更多