ios - 更改 TableView 单元格颜色将不起作用

标签 ios objective-c uitableview uicolor

尝试更改 UITableViewCell 文本 UIColour(服装单元格)将使文本变成白色且看不见,而不是仅在触摸 UITableViewCell 时,我可以看到文字。 为什么将 UIColour 设置为不是 blackColorUITableViewCell 将不起作用?

- (UITableViewCell *)tableView:(UITableView *)tableView 
         cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = 
     [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier 
                                          forIndexPath:indexPath];       
    if (!indexPath.row) {
        NSDictionary *dic= [[GlobalData sharedGlobals].categories 
                             objectAtIndex:indexPath.section];
        cell.textLabel.text = [dic objectForKey:@"title"]; // only top row showing
        cell.textLabel.font = [UIFont fontWithName:@"Arial Rounded MT Bold" 
                                              size:22];
        cell.textLabel.textColor = [UIColor colorWithRed:177 
                                                   green:218 
                                                    blue:229 
                                                   alpha:1];
        //cell.textLabel.backgroundColor = [UIColor colorWithRed:218 
                                                           green:241 
                                                            blue:245 
                                                           alpha:1];
    } else {
       NSMutableArray *typesOfSection = 
        [[GlobalData sharedGlobals].typesByCategories 
          objectAtIndex:indexPath.section];
        NSDictionary *type = [typesOfSection objectAtIndex:indexPath.row-1];
        NSString *titleOfType = [type objectForKey:@"title"];
        cell.textLabel.text = titleOfType;
        cell.textLabel.textColor = [UIColor colorWithRed:122 
                                                   green:181 
                                                    blue:196 
                                                   alpha:1];
        cell.textLabel.font = [UIFont fontWithName:@"Arial Rounded MT Bold" 
                                              size:22];

        //cell.textLabel.text = @"check";
        cell.accessoryView = nil;
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }

    return cell;
}

当这样做的时候:

cell.textLabel.textColor = [UIColor redColor];

它的工作..

最佳答案

您基本上是将单元格的文本颜色设置为白色。 RGB 值应介于 0.0 和 1.0 之间。

试试这个

[UIColor colorWithRed:122.0/255.0 green:181.0/255.0 blue:196.0/255.0 alpha:1.0];

关于ios - 更改 TableView 单元格颜色将不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22501885/

相关文章:

android - 区分 iOS 和 Android Firebase 身份验证用户

ios - 将 UISegmentedControl 添加到 UITableView

swift - 在表格 View 行的右侧显示事件指示器

ios - UITableView 自己滚动

ios - 如何使用 Alamofire 从 JSON 中提取数据

ios - 由于授权,WKWebview 无法加载 Assets 文件

ios - Alamofire httpBody 在 swift 5 中显示 500 statusCode

ios - 找不到 'AVCapturePhotoCaptureDelegate' 的协议(protocol)声明

objective-c - AVPlayerLayer 获取图像到 UIImageView 缓冲区

ios - 当在 UISearchBar 中粘贴搜索字段时,searchBar textDidChange 被调用两次