给 “a,b,c... 定位栏添加背景。。。。自定义 TABLEVIEW 的层

本文介绍如何使用 iOS 的 UITableView 进行定制化操作,包括为定位栏添加背景颜色及修改头部视图的背景色等。通过代码示例展示了如何设置背景色、字体大小以及添加额外的 UI 组件如 UILabel 和 UIView 来美化 UITableView 的显示效果。

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

    // “a,b,c... 定位栏添加背景。。。。

可以放在这个方法里面 //


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

{

 

   for(UIView *view in  [aTableView subviews])

    {

        

        if([[[view class] description] isEqualToString:@"UITableViewIndex"])

        {

            

            //[view setBackgroundColor:RGB(40, 40, 40)];

            //[view setBackgroundColor:[UIColor blackColor]];

            //[view setFont:[UIFont systemFontOfSize:14]];

           // [view setBackgroundColor:[UIColor colorWithRed:100 green:100 blue:100 alpha:0]];

        }

    }


}


///-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


//  修改 层的 背景色。。。

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

{

    NSString *sectionTitle = [self tableView:tableView titleForHeaderInSection:section];

    UIView* myView = [[UIView alloc] init];

    myView.frame = CGRectMake(0, 0, 200, 22);

    myView.backgroundColor = RGB(65, 65, 65);

    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 0, 200, 22)];

    titleLabel.textColor=[UIColor whiteColor];

    titleLabel.backgroundColor = [UIColor clearColor];

    titleLabel.text = sectionTitle;

    if ([titleLabel.text length]==0){

        return nil;

    }

    

    //

    [myView addSubview:titleLabel];

    

    UIView *blackLine = [[UIView alloc] initWithFrame:CGRectMake(0, 21, 320, 1)];

    blackLine.backgroundColor = RGB(20, 20, 20);

    [myView addSubview:blackLine];

    

    UIView *whiteLine = [[UIView alloc] initWithFrame:CGRectMake(0, 20, 320, 1)];

    whiteLine.backgroundColor = RGB(60, 60, 60);

    [myView addSubview:whiteLine];

    return myView;




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值