- Tạo CustomCell:
+ Tạo file xib:
+ sửa file ViewController.m:
- Set background color:
- Căn trái sperator:
- Clear Footer operator:
- Set height wrap label content:
- Set background selected:
- Khoá select
- Khoá kéo Scroll
+ Tạo file xib:
+ sửa file ViewController.m:
- (void)viewDidLoad {
[super viewDidLoad];
_uiTable.dataSource = self;
_uiTable.delegate = self;
[_uiTable registerNib:[UINib nibWithNibName:@"CustomCell" bundle:nil] forCellReuseIdentifier:@"MyCell"];
}
...
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyCell" forIndexPath:indexPath];
[cell.label setLineBreakMode:NSLineBreakByWordWrapping];
cell.label.numberOfLines = 0;
cell.label.text = _dataArray[indexPath.row];
cell.backgroundColor = [UIColor clearColor];
return cell;
}
...- Set background color:
- Căn trái sperator:
- Clear Footer operator:
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
// This will create a "invisible" footer
return 0.01f;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
// To "clear" the footer view
return [UIView new];
}
- Set height wrap label content:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyCell" forIndexPath:indexPath];
// label multi line:
[cell.label setLineBreakMode:NSLineBreakByWordWrapping];
cell.label.numberOfLines = 0;
cell.label.text = _dataArray[indexPath.row];
cell.backgroundColor = [UIColor clearColor];
return cell;
}
// wrap label:
-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewAutomaticDimension;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewAutomaticDimension;
}
- Set background selected:
// change background color of selected cell
UIView *bgColorView = [[UIView alloc] init];
[bgColorView setBackgroundColor:[UIColor clearColor]];
[cell setSelectedBackgroundView:bgColorView];
_contentTableView.allowsSelection = NO;
- Khoá kéo Scroll
_menuTableView.scrollEnabled = NO;
Không có nhận xét nào:
Đăng nhận xét