#import "ViewController.h"
@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic,strong) NSArray *dataSource;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"查看字体集";
[self.view addSubview:self.tableView];
}
#pragma mark - lazy
- (UITableView *)tableView {
if (!_tableView) {
_tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.estimatedRowHeight = 0.0;
_tableView.sectionHeaderHeight = 0.0;
_tableView.sectionFooterHeight = 0.0;
_tableView.estimatedSectionHeaderHeight = 0.0;
_tableView.estimatedSectionFooterHeight = 0.0;
}
return _tableView;
}
#pragma mark - lazyLoding
- (NSArray *)dataSource {
if (!_dataSource) {
_dataSource = [UIFont familyNames];
}
return _dataSource;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.dataSource.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([UITableView class])];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:NSStringFromClass([UITableView class])];
}
cell.imageView.image = [UIImage imageNamed:@"zrx4.jpg"];
cell.textLabel.text = self.dataSource[indexPath.row];
cell.detailTextLabel.text = [NSString stringWithFormat:@"这是第%ld个UITableViewCellStyleSubtitle",indexPath.row];
return cell;
}
@end
系统自己的UITableViewCell样式有四种:
1.UITableViewCellStyleDefault:

Default样式:左边一个显示图片的imageView,一个标题textLabel,没有detailTextLabel。
2.UITableViewCellStyleSubtitle:

Subtitle样式:左边一个显示图片的imageView,上边一个主标题textLabel,一个副标题detailTextLabel。主标题字体大且加黑,副标题字体小在主标题下边。
3.UITableViewCellStyleValue1:

Value1样式:左边一个显示图片的imageView,左边一个主标题textLabel,右边一个副标题detailTextLabel,主标题字体比较黑。
4.UITableViewCellStyleValue2:

Value2样式:左边一个主标题textLabel字体偏小,挨着右边一个副标题detailTextLabel,字体大且加黑。
网友评论