iphone - 更改 UITableview 中节标题的颜色

标签 iphone objective-c uitableview sectionheader

我有一个非常简单的问题(我希望如此)。如何将 UITableview 中的部分标题颜色从默认蓝色更改为黑色透明? 提前致谢。

最佳答案

这是一个老问题,但我认为答案需要更新。

此方法不涉及定义您自己的自定义 View 。
在 iOS 6 及更高版本中,您可以通过定义
轻松更改背景颜色和文本颜色

- (void)tableView:(UITableView *)tableView 
        willDisplayHeaderView:(UIView *)view 
        forSection:(NSInteger)section
委托(delegate)方法。

例如:

- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section
{
    // Background color
    view.tintColor = [UIColor blackColor];

    // Text Color
    UITableViewHeaderFooterView *header = (UITableViewHeaderFooterView *)view;
    [header.textLabel setTextColor:[UIColor whiteColor]];

    // Another way to set the background color
    // Note: does not preserve gradient effect of original header
    // header.contentView.backgroundColor = [UIColor blackColor];
}

摘 self 在这里的帖子: https://happyteamlabs.com/blog/ios-how-to-customize-table-view-header-and-footer-colors/

关于iphone - 更改 UITableview 中节标题的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2389889/

相关文章:

iphonesdk日期格式问题

objective-c - 带分页的自动 UIScrollView

objective-c - NSUserDefault 和开关

ios - 在 TableView Controller 中列出计划的通知

iphone - 如何将一个 xib 的 UIViewController View 嵌入到另一个 xib 的 View 中?

iphone - 触摸 subview 时如何取消滚动

ios - 等待进入 Controller ,直到 wifi 启用 IOS

ios - TableView 中的 Collectionview - 如何选择项目?

iOS : WHO'S in charge of refreshing UI/Screen while UITableView's scrolling?

iphone - 背景图像尺寸 iPhone