IOS学习 UITableView 基本属性

删除空白行

self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];


#import <UIKit/UIKit.h>

#define VIEW_WIDTH self.view.bounds.size.width

#define VIEW_HEIGHT self.view.bounds.size.height

@interface HomeViewController :UIViewController<UITableViewDataSource>

{

    UITableView *_tableView;

}


@property (nonatomic,retain)NSArray *listArray;


@end



@implementation HomeViewController


- (void)viewDidLoad {

    [superviewDidLoad];

    // Do any additional setup after loading the view.

    

    self.listArray = [UIFontfamilyNames];//所有字体名称

    

    _tableView = [[UITableViewalloc]initWithFrame:CGRectMake(0,20, VIEW_WIDTH, VIEW_HEIGHT-20)style:UITableViewStylePlain];

    

    //实现数据源方法

    _tableView.dataSource =self;

    

    //设置行高,默认为44

    _tableView.rowHeight =60;

    

    //设置表视图的背景色,需先清除单元格和背景视图默认的白色背景

    _tableView.backgroundView =nil; //清除背景视图默认的白色背景


//    _tableView.backgroundColor = [UIColor yellowColor];

    

    //设置表视图的图片

    _tableView.backgroundView =nil;

    UIImageView *imageView = [[UIImageViewalloc]initWithImage:[UIImageimageNamed:@"background5.jpg"]];

    _tableView.backgroundView = imageView;

    

    //设置表视图的分割线

    _tableView.separatorColor = [UIColorpurpleColor];

    _tableView.separatorStyle =UITableViewCellSeparatorStyleNone; //隐藏分割线

   /*   UITableViewCellSeparatorStyleSingleLine;单线

    UITableViewCellSeparatorStyleSingleLineEtched; ??*/

    

    //设置表视图的头部视图  HeaderView添加子视图

    UIView *headerView = [[UIViewalloc]initWithFrame:CGRectMake(0,0, VIEW_WIDTH,60)];

//    headerView.backgroundColor = [UIColor purpleColor];

    _tableView.tableHeaderView = headerView;

    

    UILabel *label = [[UILabelalloc]initWithFrame:CGRectMake(100,0, VIEW_WIDTH-200,60)];

    label.text = @"三八节快乐!";

    label.textAlignment =NSTextAlignmentCenter;

    label.backgroundColor = [UIColorcyanColor];

    [headerView addSubview:label];

    

    //设置表视图的尾部视图  FooterView

    UIView *footerView = [[UIViewalloc]initWithFrame:CGRectMake(0,0, VIEW_WIDTH,30)];

    footerView.backgroundColor = [UIColororangeColor];

    _tableView.tableFooterView = footerView;

    

    [self.viewaddSubview:_tableView];

}


#pragma mark - UITableView DataSource

//section中包含row的数量

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return_listArray.count;

}


//创建单元格

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

    static NSString *cellIndentifier =@"cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIndentifier];

    if (cell == nil) {

        cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:cellIndentifier];

    }

    NSString *fontName = [self.listArrayobjectAtIndex:indexPath.row];

    cell.textLabel.text = fontName;

    cell.textLabel.textColor = [UIColorredColor];

    cell.textLabel.font = [UIFontfontWithName:fontName size:24];

    

    //指向其中的哪一行

    NSLog(@"index row :%ld",(long)indexPath.row);

    NSLog(@"index section :%ld",(long)indexPath.section);

    

    //清除单元格默认的白色背景

    cell.backgroundColor=[UIColorclearColor];

    

    return cell;


}


//表视图中存在section的个数,默认为1

//- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

//    

//}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值