Default section head title font & color and so on

來源:互聯網
上載者:User

參考:

[1]http://stackoverflow.com/questions/5869344/uitableview-header-footer-font-color

[2]http://www.iphonedevsdk.com/forum/iphone-sdk-development/1199-default-tableview-section-header-background-color.html

UITableview可以由多個Section組成,每個section可以由若干個row,並且可以為section設定title標題,可以用來設定標題。

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;    // fixed font style. use custom view (UILabel) if you want something different

這是個UITableViewDataSource的回呼函數,當顯示完成後,除非你roloadData,而roloadData會帶來效能花費, 否則不會重新調用。因此,你也不能對即時的改變title。

這時可以通過返回一個view給Section head,這樣你就可以addsubview顯示任何你想顯示的,並且將此view做為執行個體成員,就可以做到即時改變,而不需要reloadData。

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;   // custom view for header. will be adjusted to default or specified header height

但有個問題,你如何使顯示的section 標題,跟通過titleForHeaderInSection回調顯示的一樣,就是你不清楚它所用的字型、顏色、等等資訊。所以要想顯示的跟系統一樣就需要以下資訊

Plain
fontName: Helvetica-Bold
pointSize: 18.000000
textColor: UIDeviceWhiteColorSpace 1 1
shadowColor: UIDeviceWhiteColorSpace 0 0.44
shadowOffset: CGSize 0 1


Grouped
fontName: Helvetica-Bold
pointSize: 17.000000
textColor: UIDeviceRGBColorSpace 0.298039 0.337255 0.423529
1
shadowColor: UIDeviceWhiteColorSpace 1 1
shadowOffset: CGSize 0 1


我用到的相關代碼如下:

UILabel* sectionHeadLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 0, 320, 44)];sectionHeadLabel.backgroundColor = [UIColor clearColor];sectionHeadLabel.textColor    = [UIColor colorWithRed:0.298039 green:0.337255 blue:0.423529 alpha:1.0];    sectionHeadLabel.shadowColor  = [UIColor colorWithWhite:1.0 alpha:1.0];sectionHeadLabel.shadowOffset = CGSizeMake(0, 1); sectionHeadLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:17.0f];

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.