我有一個非常簡單的問題(我希望如此)。如何將UITableview中的部分標題顏色從默認藍色更改爲黑色透明? 在此先感謝。在UITableview中更改節標題的顏色
9
A
回答
18
需要實現在的UITableViewDelegate協議這種方法:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
這裏是到documentation
鏈接...和做這樣的事情(Sub在自己的顏色):
UIView *sectionView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 22)] autorelease];
[sectionView setBackgroundColor:[UIColor blackColor]];
return sectionView;
您也可以使用整數部分替代顏色或類似的東西。我認爲這些部分的默認高度是22,但您可以隨心所欲地製作它。這是你的問題的意思嗎?希望這可以幫助。
0
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0,tableView.bounds.size.width, 30)];
if (section == 0)
[headerView setBackgroundColor:[UIColor redColor]];
else
[headerView setBackgroundColor:[UIColor clearColor]];
return headerView;
}
20
這是一個老問題,但我認爲答案需要更新。
此方法不涉及定義您自己的自定義視圖。
在iOS 6及更高版本中,您可以通過定義代理方法來輕鬆更改背景顏色和文本顏色。
例如:
- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section { // Background color view.tintColor = [UIColor blackColor]; // Text Color UITableViewHeaderFooterView *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]; }
從我這裏後摘自: https://happyteamlabs.com/blog/ios-how-to-customize-table-view-header-and-footer-colors/
相關問題
- 1. 更改UITableView節標題的顏色
- 2. UITableView - 更改節標題顏色
- 3. 顏色更改爲標題中的UITableView
- 4. 更改UITableView標題色調顏色
- 5. 更改UITableView標題的背景顏色
- 6. 更改UITableView部分標題的顏色
- 7. 如何更新的章節標題,而不UITableView的reloadData顏色
- 8. 在NavigationView中更改顏色nav_menu標題
- 9. 更改GridViewColumn標題顏色
- 10. 更改顏色標題欄
- 11. 在UITableView中更改節的背景顏色
- 12. 自動更改UITableView顏色?
- 13. UITableView如何更改顏色?
- 14. Android更改XML中的標題顏色
- 15. 更改WinForm中標題欄的顏色
- 16. Nimbus更改標籤標題的顏色
- 17. 如何設置UITableView節標題中的字體顏色?
- 18. 更改標題顏色多中心prestashop
- 19. UITableView - 節標題。如何更改文字?
- 20. visual C#更改標籤標題顏色
- 21. 如何更改在UITableView中選擇的單元格標題顏色
- 22. 更改標題的顏色RichTextBox VB.NET
- 23. 更改DatePicker的標題文字顏色
- 24. 更改標題UIActivityController的文本顏色
- 25. 如何更改objectchoicefield標題的顏色
- 26. 更改UIButton的默認標題顏色
- 27. 更改顏色條標題的位置
- 28. 如何更改facet_wrap標題的顏色?
- 29. 更改NSWindow標題文本的顏色
- 30. 更改NSWindow標題欄的顏色
這是一個類似的問題:http://stackoverflow.com/questions/813068/uitableview-change-section-header -color – nylund 2011-12-01 13:46:39