更改 UITableViewCell 中 UILabel 的文本颜色 [英] Changing the text color of UILabel in UITableViewCell

查看:16
本文介绍了更改 UITableViewCell 中 UILabel 的文本颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在单击按钮时更改 UITableViewCell 中包含的 UILabel 的文本颜色.我创建了一个 UIColor 对象,它在按钮点击时设置为指定的颜色并调用 UITableView reloadData 方法,即使颜色没有改变.我应该如何实施?

I am required to change the text color of the UILabel which is contained in the UITableViewCell on a button click. I have created a UIColor object, which is set to specified color on the button click and called the UITableView reloadData method, even then the color is not changing. How should I implement this?

推荐答案

我假设您想更改表格中所有行的颜色.(如果您只想更改单行,则需要它的 indexPath).

I assume that you want to change the color of all rows in your table. (If you just want to change a single row, you will need its indexPath).

创建一个 BOOL 变量来跟踪颜色状态.在您的按钮单击例程中,适当地设置此值并执行 [tableView reloadData].

Create a BOOL variable that keeps track of the color state. In your button click routine, set this value appropriately and do a [tableView reloadData].

cellForRowAtIndexPath 中,您需要每次检查变量并设置两种状态的颜色.两种方式都必须这样做,否则滚动时单元格的状态将不可预测.

In cellForRowAtIndexPath you need to check the variable and set the color for both states each time. It is essential that you do it both ways, otherwise the state of the cell will be unpredictable when scrolling.

这篇关于更改 UITableViewCell 中 UILabel 的文本颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆