日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

iOS- 如何改变section header

發布時間:2023/12/13 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 iOS- 如何改变section header 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

希望這個從UITableViewDelegate協議里得到的方法可以對你有所幫助:

- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {UIView *headerView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)] autorelease];if (section == integerRepresentingYourSectionOfInterest)[headerView setBackgroundColor:[UIColor redColor]];else[headerView setBackgroundColor:[UIColor clearColor]];return headerView; }

使用任何你喜歡UIColor代替[UIColor redColor]。你可能還希望調整headerView的尺寸。


DoctorG
這是改變文本顏色的方法:

UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(10, 3, tableView.bounds.size.width - 10, 18)] autorelease]; label.text = @"Section Header Text Here"; label.textColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.75]; label.backgroundColor = [UIColor clearColor]; [headerView addSubview:label];

whyoz
不要忘記從委托添加這段代碼,否則在某些情況下視圖將被切斷或者出現在table后面,相對于視圖/標簽的高度。

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

Leszek ?arna
如果你想自定義header顏色,可以這樣做:

[[UITableViewHeaderFooterView appearance] setTintColor:[UIColor redColor]];

這個方法在iOS 6.0.以上都很好用。


Maulik
這是在標題視圖添加圖片的方法:

- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {UIView *headerView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)] autorelease];UIImageView *headerImage = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"top-gery-bar.png"]] autorelease];headerImage.frame = CGRectMake(0, 0, tableView.bounds.size.width, 30);[headerView addSubview:headerImage];return headerView; }

William Jockusch
如果你不想建立自定義視圖,你也可以這樣改變顏色(需要在iOS6里):

-(void) tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section {if ([view isKindOfClass: [UITableViewHeaderFooterView class]]) {UITableViewHeaderFooterView* castView = (UITableViewHeaderFooterView*) view;UIView* content = castView.contentView;UIColor* color = [UIColor colorWithWhite:0.85 alpha:1.]; // substitute your color herecontent.backgroundColor = color;} }

Dj S
這是常見的問題,我認為答案需要更新一下。
這個方法不涉及定義和創建自定義視圖。在iOS 6以上,你可以通過以下方法輕松改變背景色和文本色:

- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section

委托方法
例如:

- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section {// Background colorview.tintColor = [UIColor blackColor];// Text ColorUITableViewHeaderFooterView *header = (UITableViewHeaderFooterView *)view;[header.textLabel setTextColor:[UIColor whiteColor]];// Another way to set the background color// Note: does not preserve gradient effect of original header// header.contentView.backgroundColor = [UIColor blackColor]; }

orbv
通過UITableViewHeaderFooterView設置背景色的方法已經被廢棄了。請用contentView.backgroundColor代替。

轉載于:https://www.cnblogs.com/mcj-coding/p/3696923.html

總結

以上是生活随笔為你收集整理的iOS- 如何改变section header的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。