三十八 tableView修改索引区域索引数据的颜色

本文介绍了如何使用UITableView在iOS应用中设置索引的颜色,包括索引字体颜色、整体背景颜色和点击时的背景颜色。这些设置既可以在初始化时进行,也可以在代理方法中实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

既可以在初始化的时候设置,也可以在代理方法中设置,有改变数据的颜色,和改变背景的颜色

1,在初始化的时候直接设置如下 _tableView.sectionIndexColor = [UIColor greenColor];

 _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, W,H - 64) style: UITableViewStyleGrouped];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.backgroundColor = [UIColor clearColor];
        _tableView.sectionIndexColor = [UIColor greenColor];//索引字体背景颜色
        _tableView.sectionIndexBackgroundColor = [UIColor redColor];//索引整体背景颜色
        _tableView.sectionIndexTrackingBackgroundColor = [UIColor blueColor];//索引点击时的背景颜色

2,是在代理方法中设置

//section右侧index数组
-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{
    tableView.sectionIndexColor =[UIColor redColor];//索引字体颜色
    tableView.sectionIndexBackgroundColor = [UIColor grayColor];//索引背景颜色
    tableView.sectionIndexTrackingBackgroundColor = [UIColor blueColor];//点击后的背景颜色
    return _array;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值