Ios UITableView,UILabel文本颜色在选择行时不更改?
我有Ios UITableView,UILabel文本颜色在选择行时不更改?,ios,objective-c,xcode,ios7,uilabel,Ios,Objective C,Xcode,Ios7,Uilabel,我有UITableView,我在UITableView中有四个带有文本(白色)的标签,当我选择要在blackColor中更改标签textcolor的行时,你应该使用didSelectRowAtIndexPathtableView委托方法: - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // Change your text color here
UITableView
,我在UITableView
中有四个带有文本(白色)的标签,当我选择要在blackColor
中更改标签textcolor
的行时,你应该使用didSelectRowAtIndexPath
tableView委托方法:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Change your text color here.
}
在
单元格中,使用以下代码:
选择:
label.highlightedTextColor = [UIColor blackColor];
label.textColor = [UIColor whiteColor];
正常:
label.highlightedTextColor = [UIColor blackColor];
label.textColor = [UIColor whiteColor];
默认情况下,ui标签的textColor
为blackColor
。您的标签的textColor
如何更改为whiteColor
无论如何,您可以这样更改标签的textColor
:
label.textColor = [UIColor blackColor];
祝你一切顺利 没有你的代码,很难说你错在哪里?但我把我的逻辑放在这里
首先在cellforrowatinexpath
中为每个UILabel
提供标签,如
lbl1.tag = 101;
lbl2.tag = 102;
.
.
.
然后
- (void)tableView:(UITableView *)tv didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [self tableView:tv cellForRowAtIndexPath:indexPath];
UILabel *label = (UILabel*)[cell viewWithTag:101]; // you can get label like
[label setTextColor:RedColor]; // set as you want
.
.
// write for each label
}
并将其设置为取消选择单元格时的颜色
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [self tableView:tv cellForRowAtIndexPath:indexPath];
UILabel *label = (UILabel*)[cell viewWithTag:101]; // you can get label like
[label setTextColor:RedColor]; // set color as it is
.
.
.
// write for each label
}
我只在最后一行尝试了更改。使用标记或indexPath获取所选单元格并对其进行更改。如果在tableview Selecting中不起作用,则需要在didSelectRowAtIndexPath方法中使用所选索引,和更改UILabel的文本颜色。我创建了UILabel及其文本颜色,然后将子视图添加到cell.contentview。现在我正在尝试更改didselectrow中的颜色,但它没有更改,选择任何行的最后一行中只显示颜色更改我只创建了一个uilabel,标记为indexpath.row,但不是working@RameshKumar-那就跟我来。是的,我想这个标签会起作用的,因为标签在手机内…@iPatel我试过了,但没有working@RameshKumar-然后把代码放在这里。或者您是否已将[cell viewWithTag:101]
更改为[cell viewWithTag:indexPath.row]
?