我正在尝试添加一个UITableView与附加图像(LHR-SYD / 372 结果)类似的固定透明标题。这是 xcode/ios 中的“内置”组件还是如何完成的?

我正在尝试添加一个UITableView与附加图像(LHR-SYD / 372 结果)类似的固定透明标题。这是 xcode/ios 中的“内置”组件还是如何完成的?

使用这些方法,
- (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;
}
您可以使用此代码设置标题视图的高度
您可以更改默认标题视图 bg:
- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section {
UITableViewHeaderFooterView *header = (UITableViewHeaderFooterView *)view;
header.backgroundView.backgroundColor = [header.backgroundView.backgroundColor colorWithAlphaComponent:1];
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *transparentView=[[UIView alloc]initWithFrame:CGRectMake(0,0,320,10)];
transparentView.backGroundColor=[UIColor clearColor];
return transparentView;
}
这实际上是 a 的默认标头UITableView。您所要做的就是实现该titleForHeaderInSection方法,它就会出现。查看该方法的文档,它有很大帮助
是的,这是内置的。随附的屏幕截图是UITableView使用部分的。
您还可以自定义部分标题的视图。请参阅[tableView:viewForHeaderInSection:](https://developer.apple.com/documentation/uikit/uitableviewdelegate/1614901-tableview)。但是,您看到的是默认视图,因此您只需要实现部分和titleForHeaderInSection.