我希望增加UITableView的表头和单元格之间的间距。
我已经进行了很多搜索,并找到了以下解决方案:
- (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;
}
我尝试了这段代码,模拟器上运行得很好,但是在我的设备上运行时没有显示任何间隔。
以下是模拟器的快照:(我可以看到标题和单元格之间的间隔...) : 提前感谢。