我使用tabelView的一些背景顏色和樣式進行分組。部分標題中的文本不清楚,所以我需要修改文本顏色,以便標題文本應該可見。 我想知道我們是否可以更改標題文本的顏色和大小?我們如何更改tableview標題的字體?
4
A
回答
9
添加到terente的回答是:
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
if (section == 0) {
CGRect screenRect = [[UIScreen mainScreen] applicationFrame];
UIView* headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, screenRect.size.width, 44.0)];
//headerView.contentMode = UIViewContentModeScaleToFill;
// Add the label
UILabel *headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(10.0, -5.0, 300.0, 90.0)];
headerLabel.backgroundColor = [UIColor clearColor];
headerLabel.opaque = NO;
headerLabel.text = @"Header";
headerLabel.textColor = [UIColor blackColor];
headerLabel.highlightedTextColor = [UIColor blackColor];
//this is what you asked
headerLabel.font = [UIFont boldSystemFontOfSize:17];
headerLabel.shadowColor = [UIColor clearColor];
headerLabel.shadowOffset = CGSizeMake(0.0, 1.0);
headerLabel.numberOfLines = 0;
headerLabel.textAlignment = UITextAlignmentCenter;
[headerView addSubview: headerLabel];
[headerLabel release];
// Return the headerView
return headerView;
}
else return nil;
}
可以使用[UIFont fontWithName:@"<name of your font>" size:24.0];
其他字體
5
只實現
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
,並返回您的自定義視圖頭。
編輯:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIImageView *headerTitleView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, kSectionHeaderHeight)];
[headerTitleView setImage:sectionHeaderBackgroundImage];
UILabel *sectionTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake((self.view.frame.size.width - 38)/2, 5, 38, kSectionHeaderHeight - 10)];
sectionTitleLabel.textColor = [UIColor redColor];
sectionTitleLabel.backgroundColor = [UIColor clearColor];
sectionTitleLabel.textAlignment = UITextAlignmentCenter;
sectionTitleLabel.text = @"A";
sectionTitleLabel.font = [UIFont fontWithName:@"yourFont" size:13];
[sectionTitleLabel setAdjustsFontSizeToFitWidth:YES];
[headerTitleView addSubview:sectionTitleLabel];
return headerTitleView;
}
0
- (void) tableView : (UITableView*) tableView willDisplayHeaderView : (UIView*) view forSection : (NSInteger) section{
[((UITableViewHeaderFooterView) *view).textLabel setFont:(UIFont...)];
}
,你可以從其他的表中設置的文本標籤查看委託方法。
0
- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section {
[((UITableViewHeaderFooterView *) view).textLabel setFont:[UIFont fontWithName:@"Your-Font-Name" size:((UITableViewHeaderFooterView *) view).textLabel.font.pointSize]];
}
注:
- 這將設置字體爲自定義字體,但保持
pointSize
相同。 - 也適用於
willDisplayFooterView
。 - 不要忘記將
Your-Font-Name
更改爲您的字體。
0
- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section {
if ([view isKindOfClass:[UITableViewHeaderFooterView class]]) {
UITableViewHeaderFooterView *headerView = (UITableViewHeaderFooterView*)view;
[headerView.textLabel setFont:[UIFont fontWithName:@"Gotham Book" size:16.0f]];
}}
我們可以使用header.textlabel對象更改其他 「的UILabel」 屬性該標籤。
相關問題
- 1. 如何更改JFrame標題的字體?
- 2. 我們可以更改MFmessagecomposeViewcontroller導航標題字體
- 3. 如何更改TabItem的標題字體而不更改內容的字體?
- 4. 如何在viewForHeaderInSection的tableview中動態更改標題標題?
- 5. 如何粗體和更改圖表的字體大小標題
- 6. 更改字體標籤中間標題
- 7. 如何僅更改qcombobox標籤/標題的字體?
- 8. 更改JavaFX TableView的字體大小
- 9. 我們是否需要更改標題?
- 10. 更改UINavigationBar標題的字體
- 11. 更改WPF中的標題字體OxyPlot
- 12. 如何更改窗體標題的字體大小和字體系列?
- 13. C#如何更改標籤的字體
- 14. 我們如何動態更改DataGrid的字體大小和字體系列?
- 15. Sencha touch2:如何將默認字體更改爲我們的自定義字體?
- 16. JavaFX 2 TableView標題字體顏色
- 17. (iPhone)如何更改tableview中一行的字體大小
- 18. 我們如何更改datagridview標題名稱?
- 19. IOS更改按鈕標題字體
- 20. 更改NSTableView標題字體顏色
- 21. JFreeChart MultiPiePlot更改標題字體顏色
- 22. Kivy:更改RstDocument標題字體
- 23. 更改MFMailComposeViewController navigationBar標題字體
- 24. 如何在TableView中更改按鈕的標題(Swift)
- 25. 如何更改以下jtable標題的字體
- 26. 如何更改TableViewer標題的字體和樣式
- 27. 如何僅更改QGroupBox標題的字體?
- 28. 如何更改AppCompat中ActionBar標題的字體23
- 29. 如何更改TCheckBox,TRadioButton,TGroupBox上的標題字體顏色?
- 30. 如何更改標題和alertController的字體和顏色?
感謝xs2bush爲您的快速響應,現在我可以將標題標題顏色 – User97693321
更改爲'headerLabel.textColor = [UIColor blackColor];'爲您想要的顏色。 –
不要忘記實現'tableView:heightForHeaderInSection:'或者你的部分頭部不適合你的新視圖。 – Andrew