【发布时间】:2013-07-30 10:25:30
【问题描述】:
我想增加 UITableView 的 header 和 cell 之间的差距。
我搜索了很多,我找到了这个解决方案,
- (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;
}
我试过这段代码,它在模拟器中运行良好,但没有显示任何空格, 当我在我的设备上运行它时。
这是模拟器的快照:(我可以看到 Header 和单元格之间的间隙..) : 提前致谢。
【问题讨论】:
-
您使用的是哪种设备?
-
@krunal 增加你的 'heightForHeaderInSection' 高度,比如返回 60.0。
-
您使用的是哪个设备和模拟器...是指 4 英寸还是 3.5 英寸?
-
3.5" 模拟器和设备iphone 4s
标签: iphone ios ipad uitableview