Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

space between header and table cell

I want to increase gap between header and cell of UITableView.

I have searched a lot and i found this solution,

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 20.0;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
   //Adding UIView and it's Background Image...
    UIView *tempView=[[UIView alloc]initWithFrame:CGRectMake(0,0,300,20)];
    UIImageView *BgImg=[[UIImageView alloc]initWithFrame:CGRectMake(0,0,300,20)];
    BgImg.image= [UIImage imageNamed:@"venueTitleBg.png"];
    [tempView addSubview:BgImg];

    //Adding UIImageView...
    UIImageView *flag=[[UIImageView alloc]initWithFrame:CGRectMake(10,3,20,12)];
    flag.image= [UIImage imageNamed:@"flag_small_united-kingdom.png"];
    [tempView addSubview:flag];

    //Adding UILabel...
    UILabel *tempLabel=[[UILabel alloc]initWithFrame:CGRectMake(40,1,300,15)];
    tempLabel.backgroundColor=[UIColor colorWithRed:15.0/255.0 green:15.0/255.0 blue:30.0/255.0 alpha:1.0];
    tempLabel.textColor=[UIColor whiteColor];
    tempLabel.font=[UIFont systemFontOfSize:11];
    tempLabel.text=@"United Kingdom";
    [tempView addSubview: tempLabel];

    return tempView;
}

I tried this code, it is working fine in simulator but it doesn't show any spaces, when i run it on my device.

Here is snapshot of Simulator: (I can see gap between Header and cell..) : Thanks in advance.

like image 329
Krunal Avatar asked May 21 '26 06:05

Krunal


1 Answers

Try this:

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 50.0;
}
like image 139
user2545330 Avatar answered May 22 '26 18:05

user2545330



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!