我正在尝试添加一个UITableView
与附加图像(LHR-SYD / 372 结果)类似的固定透明标题。这是 xcode/ios 中的“内置”组件还是如何完成的?
问问题
5296 次
5 回答
7
使用这些方法,
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;
上述设置视图的方法。
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;
上面设置标题的方法。看到这个,
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UILabel *lbl = [[[UILabel alloc] init] autorelease];
lbl.textAlignment = UITextAlignmentLeft;
lbl.text=@"LHR-SYD / 372 Results";
return lbl;
}
通过使用上述方法,您可以向 headerview 添加不同的对象。
(或者)
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
return @"LHR-SYD / 372 Results";
}
我认为这是您的要求。
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 30;
}
您可以使用此代码设置标题视图的高度
于 2013-04-30T11:36:26.227 回答
2
您可以更改默认标题视图 bg:
- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section {
UITableViewHeaderFooterView *header = (UITableViewHeaderFooterView *)view;
header.backgroundView.backgroundColor = [header.backgroundView.backgroundColor colorWithAlphaComponent:1];
}
于 2015-07-01T09:27:07.053 回答
1
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *transparentView=[[UIView alloc]initWithFrame:CGRectMake(0,0,320,10)];
transparentView.backGroundColor=[UIColor clearColor];
return transparentView;
}
于 2013-04-30T11:38:47.310 回答
1
这实际上是 a 的默认标头UITableView
。您所要做的就是实现该titleForHeaderInSection
方法,它就会出现。查看该方法的文档,它有很大帮助
于 2013-04-30T11:39:29.303 回答
0
是的,这是内置的。随附的屏幕截图是UITableView
使用部分的。
您还可以自定义部分标题的视图。请参阅[tableView:viewForHeaderInSection:]
(https://developer.apple.com/documentation/uikit/uitableviewdelegate/1614901-tableview)。但是,您看到的是默认视图,因此您只需要实现部分和titleForHeaderInSection
.
于 2013-04-30T11:40:41.640 回答