xcode 修复了 UITableView 中的透明标题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16298891/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 03:18:21  来源:igfitidea点击:

Fixed transparent header in a UITableView

iphoneiosobjective-cxcodeuitableview

提问by user1448401

I am trying to add a Fixed transparent header in a UITableViewsimilar to the one on the attached image (LHR-SYD / 372 Results). Is this a "built in" component in xcode/ios or how is it done ?

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

an image of an ios app that has a fixed transparent header on top of a uitableview

ios 应用程序的图像,在 uitableview 顶部有一个固定的透明标题

回答by Balu

use these methods ,

使用这些方法,

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section; 

above method for setting the view.

以上方法设置视图。

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section; 

above method for setting the title . see this one ,

以上设置标题的方法。看到这个,

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UILabel *lbl = [[[UILabel alloc] init] autorelease];
    lbl.textAlignment = UITextAlignmentLeft;
    lbl.text=@"LHR-SYD / 372 Results";
    return lbl;
}

by using above method you can add different objects to your headerview.

通过使用上述方法,您可以向 headerview 添加不同的对象。

(OR)

(或者)

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    return @"LHR-SYD / 372 Results";
}

this one your Requirement i think so.

这是您的要求,我认为是。

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

you can set height of the header view using this code

您可以使用此代码设置标题视图的高度

回答by Yedidya Reiss

You can change the default header view bg:

您可以更改默认标题视图 bg:

 - (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section {
    UITableViewHeaderFooterView *header = (UITableViewHeaderFooterView *)view;
    header.backgroundView.backgroundColor = [header.backgroundView.backgroundColor colorWithAlphaComponent:1];
}

回答by BhushanVU

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{

  UIView *transparentView=[[UIView alloc]initWithFrame:CGRectMake(0,0,320,10)];
  transparentView.backGroundColor=[UIColor clearColor];
  return transparentView;

}

回答by Clint Warner

That is actually the default header for a UITableView. All you have to do is implement the titleForHeaderInSectionmethod and it will appear. Check out the documentation for that method, it helps a lot

这实际上是UITableView. 您所要做的就是实现该titleForHeaderInSection方法,它就会出现。查看该方法的文档,它有很大帮助

回答by Kasper Munck

Yes, that is built in. The attached screenshot is of a UITableViewthat uses sections.

是的,这是内置的。附加的屏幕截图是UITableView使用部分的。

You can also customise the view of a section's header. Refer to [tableView:viewForHeaderInSection:](https://developer.apple.com/documentation/uikit/uitableviewdelegate/1614901-tableview). However, what you see is the default view so you only have to implement sections and titleForHeaderInSection.

您还可以自定义部分标题的视图。请参阅[tableView:viewForHeaderInSection:]https://developer.apple.com/documentation/uikit/uitableviewdelegate/1614901-tableview)。但是,您看到的是默认视图,因此您只需实现部分和titleForHeaderInSection.