【问题标题】:Modify colors of buttons connected to a IBoutletCollection not working修改连接到 IBoutletCollection 的按钮的颜色不起作用
【发布时间】:2014-10-18 12:59:34
【问题描述】:

我有这段代码应该修改连接到 IBoutletCollection 的 24 个按钮的颜色:

在 .h 文件中:

@property (nonatomic, strong) IBOutletCollection(UIButton) NSArray *buttons;

在 .m 文件中:

for (UIButton *label in buttons) {        
    label.layer.borderWidth = 1.5f;
    label.layer.borderColor = (__bridge CGColorRef)([UIColor colorWithRed:87.0/255.0 green:49.0/255.0 blue:42.0/255.0 alpha:1]);
    label.layer.backgroundColor = (__bridge CGColorRef)([UIColor colorWithRed:134.0/255.0 green:98.0/255.0 blue:98.0/255.0 alpha:1]);
    }

IBOutletCollection 连接到我视图中现有的 24 个按钮,最初是灰色的,当我运行这个函数来修改按钮的颜色时,它们都变成了白色,我该如何解决这个问题?

【问题讨论】:

    标签: objective-c iboutlet iboutletcollection


    【解决方案1】:

    这样使用

     [[myButton layer] setBorderWidth:2.0f];
     [[myButton layer] setBorderColor:[UIColor colorWithRed:87.0/255.0 green:49.0/255.0 blue:42.0/255.0 alpha:1].CGColor];
     [myButton setTitleColor:[UIColor colorWithRed:150.0/256.0 green:150.0/256.0 blue:150.0/256.0 alpha:1.0]]
    

    【讨论】:

    • 好的 对于背景颜色,我设置背景颜色,现在我应该为边框宽度和边框颜色使用什么?
    • 首先检查是否有颜色,然后使用 [[myButton layer] setBorderWidth:2.0f]; [[myButton layer] setBorderColor:[UIColor greenColor].CGColor];
    • 如果它有效。请投票支持我的问题并勾选我的答案。谢谢
    • 是的,这种方法有效,但问题是边框的颜色我必须放某种特殊的颜色,我相信只能使用 RGB 或 HEX 得到这种东西,你有还有什么建议吗?
    • 嘿伙计,它有效我试试这个:[[label layer] setBorderColor:[UIColor colorWithRed:74.0/255.0 green:49.0/255.0 blue:42.0/255.0 alpha:1].CGColor];跨度>
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-28
    • 1970-01-01
    • 2018-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多