5
Có một chút khó khăn khi cố gắng tạo tiêu đề bảng ios tùy chỉnh. tiêu đề của tôi là cao 30px và tôi đang sử dụng mã này để tạo ra chúng:các ô chồng chéo tiêu đề tùy chỉnh trong nhóm
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
NSString *sectionTitle = [self tableView:tableView titleForHeaderInSection:section];
if (sectionTitle == nil) {
return nil;
}
// Create label with section title
UILabel *label = [[UILabel alloc] init] ;
label.frame = CGRectMake(0, 0, 140, 30);
label.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"header_gradient.png"]];
label.textColor = [UIColor whiteColor];
label.shadowColor = [UIColor whiteColor];
label.shadowOffset = CGSizeMake(0.0, 1.0);
label.font = [UIFont boldSystemFontOfSize:12];
label.text = sectionTitle;
// Create header view and add label as a subview
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 140, 30)];
[view addSubview:label];
return view;
}
- (CGFloat)tableView:(UITableView *)tableViewheightForHeaderInSection:(NSInteger)section {
return 30;
}
Nó gần như làm việc, nhưng tiêu đề của tôi dường như colide với các tế bào/tiêu đề bên dưới chúng:
Can bất cứ ai chỉ cho tôi đi đúng hướng để dọn dẹp các tiêu đề ở đây?
Cảm ơn trước
Nó thực sự nên '- (CGFloat) tableView: (UITableView *) tableView heightForHeaderInSection: (NSInteger) phần' – omz
đúng. Khai báo đúng là như sau (từ tài liệu): - (CGFloat) tableView: (UITableView *) tableView heightForHeaderInSection: (NSInteger) phần - nếu bạn đang chú ý gần, có một [không gian] mất tích giữa tableView và heightForHeaderInSection .. Hoàn toàn bỏ lỡ rằng lần đầu tiên xung quanh, do đó tại sao tôi cho rằng trường hợp lạc đà đã tắt. Tôi đã cập nhật câu trả lời. Cảm ơn vì đã bắt! –
cảm ơn vì sự giúp đỡ ... Tôi đã phát điên cố gắng tìm ra lý do tại sao điều đó không hiệu quả! – akhalsa