删除空白行
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{
//
//}