TableView(三)索引

一索引相关属性

 //索引相关属性
    //设置默认时索引字符的的颜色
    //tableView.sectionIndexColor = [UIColor redColor];
    //选中时索引条的背景色
   // tableView.sectionIndexTrackingBackgroundColor = [UIColor lightGrayColor];
    //设置默认时,索引条的背景颜色
   // tableView.sectionIndexBackgroundColor = [UIColor yellowColor];

二.索引相关代理方法

/多少组
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return array.count;
    
}
//每组多少行
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 10;
}
//cell
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSString *cellId = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (!cell) {
        
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellId];
    }
    cell.textLabel.text = [NSString stringWithFormat:@"我是第%@组第%ld行",array[indexPath.section],indexPath.row];
    return cell;
}
//组标题
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    
    return array[section];
}
//返回一个索引数组
-(NSArray<NSString *> *)sectionIndexTitlesForTableView:(UITableView *)tableView{
    
    return array;
}
//点击索引时的委托方法
-(NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index{
    
    NSLog(@"点击了标题是%@,点击了index---%ld",title,index);
    
    lable.isAlpha = YES;
    lable.text = [NSString stringWithFormat:@"%@",title];
    
    return index;
}
//设置索引字体大小
-(void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section {
    for (UIView *view in [tableView subviews]) {
        if ([view isKindOfClass:[NSClassFromString(@"UITableViewIndex") class]]) {
            // 设置字体大小
            [view setValue:[UIFont systemFontOfSize:20]forKey:@"_font"];
            //设置view的大小
            view.bounds = CGRectMake(0, 0, 30,30);
            //单单设置其中一个是无效的
        }
    }
    
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值