2016-07-21 57 views

回答

1

爲此,你需要添加和導入

#import <QuartzCore/QuartzCore.h> 

之後按照以下步驟

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 
{ 
    UIView *section = [[UIView alloc]init]; 
    section.frame = CGRectMake(0, 0, tableview.frame.size.width, height); 
    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageWithName:@"imageName"]]; 
    imageView.frame = CGRectMake(0, 0, YOUR_WIDTH, YOUR_HEIGHT); //set your frame 
    [section addSubview:imageView];  

    labelSection = [[UILabel alloc]init]; 
    labelSection.textAlignment = NSTextAlignmentLeft; 
    labelSection.frame = CGRectMake(10, 5, tableview.frame.size.width, 20); 
    [labelSection setBackgroundColor:[UIColor clearColor]]; 
    [labelSection setFont:[UIFont boldSystemFontOfSize:15]]; 
    NSString *name = @"section title"; 
    labelSection.text = name; 
    [labelSection setTextColor:[UIColor blackColor]]; 
    [section addSubview:labelSection]; 


    section.layer.borderWidth = 2.0f; 
    section.layer.cornerRadius = 1.0f; 
    section.layer.masksToBounds = YES; 
    section.layer.borderColor=[UIColor lightGrayColor].CGColor; 

    return section; 
} 

如果你想設置的行高

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    return 44; //It default size.If you want to change to other size you can change. 
    //OR 
// return 90; //Set to your needed size 
} 
+0

不會將邊界添加到所有單元而不是段? –

+0

現在我編輯了我的答案。謝謝Bhumit Mehta。 – user3182143

相關問題