gpt4 book ai didi

iphone - UIButton setTitleColor 和 setImage 不起作用

转载 作者:行者123 更新时间:2023-12-03 18:38:33 25 4
gpt4 key购买 nike

我正在为我的 iPhone 项目使用 StoryBoard 功能。在 Storyboard中,我有一个 View Controller ,其中包含使用原型(prototype)单元的 TableView 。在原型(prototype)单元内部,我有一个 UIButton(圆角矩形)连接到子类 UIButton 类。 tableview从数组中获取数据,并将数据打印在cellForRowAtIndexPath中。

在 cellForRowAtIndexPath 内,我有条件地修改单元格的外观。这是我开始遇到问题的时候。我能够成功更改按钮的文本。但是,如果我尝试更改按钮的图像,请使用:

[cell.myButton setImage:[UIImage imageNamed:@"mynewimage.png"] forState:UIControlStateNormal];

图像发生变化,但文字消失。

如果我尝试更改按钮的文本颜色,请使用:

[cell.myButton setTitleColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:.77] forState:UIControlStateNormal]

什么也没发生。颜色保持不变(除非我也尝试更改图像,在这种情况下它会完全消失)。

我感觉我在这里做了一些根本错误的事情——你有什么建议吗?

最佳答案

使用

- (void)setBackgroundImage:(UIImage *)image forState:(UIControlState)state;   

更改图像并保留文本

使用

btn.titleLabel.textColor = yourcolor;

更改文本颜色

关于iphone - UIButton setTitleColor 和 setImage 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10479977/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com