IOS UITableView 表示图

1.表视图继承于UIScrollView 是可以滚动的

2.表示图的每一条数据都是显示在UITableViewCell对象中

3.表示图可以分区显示数据,每个分区称为一个section ,每一行称为row 编号都是从0 开始

4.重要的属性  style样式 : plain,group    分割线 separatorStyle  分割线的颜色 separatorColor  行高 rowHeight

 

UITableView *tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, self.view.frame.size.height-64)style:UITableViewStylePlain];
    tableview.rowHeight=44;//UITableView 的高度
    tableview.separatorColor = [UIColor redColor];//设置分割线的颜色
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 30, 60, 60)];
    [view setBackgroundColor:[UIColor cyanColor]];//背景颜色
    [self.view addSubview:view];
    [view release];
    tableview.tableHeaderView=view;

nav.navigationBar.barTintColor = [UIColor greenColor];//导航栏文字的颜色


5.//设置头标题的高度

//设置脚标题的高度
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 30;<pre name="code" class="objc">//设置行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            return  40;
        }
        else if (indexPath.row == 1){
            return  80;
            
        }
        else if (indexPath.row == 2){
            return  100;
        }
    }
    
    return 40;
}

<pre name="code" class="objc" style="color: rgb(0, 143, 0); font-size: 18px;">6.<span style="font-family: 'Heiti SC Light';">//设置头标题的名称</span>
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;{ if (section == 0) { return @"A"; } return @"B"; return @"通讯录";}

 

}7.//右侧添加一个索引表- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{ NSMutableArray *arr = [NSMutableArray array]; for (int i = 65; i <= 90; i++) { [arr addObject:[NSString stringWithFormat:@"%c", i]]; } return arr;}
 

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 30;
}
8.返回五个section

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 5;//五个section
}

//第一种:当前视图添加到父视图的时候(布局他的子视图)

//第二种 : 当前视图改变坐标时,

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        
        self.imagesView1 = [[UIImageView alloc]initWithFrame:CGRectZero];
        [_imagesView1 setBackgroundColor:[UIColor redColor]];
        [self.contentView addSubview:_imagesView1];
        [_imagesView1 release];
        
        
        self.titleLable = [[UILabel alloc]initWithFrame:CGRectZero];
        [self.contentView addSubview:_titleLable];
        [_titleLable release];
        
        
        self.timeLable = [[UILabel alloc]initWithFrame:CGRectZero];
        [self.contentView addSubview:_timeLable];
        [_timeLable release];
        
        self.datailLable = [[UILabel alloc]initWithFrame:CGRectZero];
        [self.contentView addSubview:_datailLable];
        [_datailLable release];
        
     
        
    }
    return self;
}
- (void)layoutSubviews{
    [super layoutSubviews];
    [self.imagesView1 setFrame:CGRectMake(10, 5, 60, 60)];
    [self.titleLable setFrame:CGRectMake(80, 5, 100, 30)];
    [self.timeLable setFrame:CGRectMake(250, 40, 100, 20)];
    [self.datailLable setFrame:CGRectMake(80, 45, 30, 30)];

}








  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值