2012-01-05 14 views
10

Chcę dostosować nagłówek sekcji TableView i pozostawić domyślny kolor tła. Używam sekcji - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger). Muszę zmienić rozmiar czcionki w zależności od urządzenia (iPad lub iPhone). W tym celu wywołaj następną funkcję:Jaki jest domyślny kolor tła nagłówka tabeli TableView na iPhonie?

[UIColor colorWithHue: 0.6 saturation: 0.33 brightness: 0.69 alpha: 0.6].

Ale znalazłem te wartości ręcznie.

Odpowiedz

23

domyślna tableview sekcji nagłówka kolor tła dla ios7 jest

Objective-C 
[UIColor colorWithRed:247/255.0f green:247/255.0f blue:247/255.0f alpha:1.0f] 

Swift 
UIColor(red: 247/255, green: 247/255, blue: 247/255, alpha: 1) 
+0

jako wszystkie składniki koloru są identyczne (247/255), co jest prostszą zmianą natywny to: 'UIColor (biały: 0.97, alfa: 1)' gdzie 0.97 ~ 247/255 –

0

Co robiłem w jednej z moich aplikacji jest stworzenie tekst tak:

NSString *sectionTitle = @"YOUR TITLE HERE"; 
CGSize sz = [sectionTitle sizeWithFont:[UIFont boldSystemFontOfSize:20.0f] 
        constrainedToSize:CGSizeMake(290.0f, 20000.0f) 
         lineBreakMode:UILineBreakModeWordWrap]; 

CGFloat height = MAX(sz.height, 20.0f); 

CGRect sectionFrame = CGRectMake(0.0, 0.0, 320.0, height); 

użyłem 290 dla szerokości więzów dać lokatorów etykieta na obu stronach. I następnie wykorzystywane rozciągliwej obraz tak:

UITableViewHeaderImage

i skalowane w celu dopasowania tekstu w nagłówku:

UIImage *headerImage = [UIImage imageNamed:@"sectionheaderbackground.png"]; 
    UIImage *stretchableImage = [headerImage stretchableImageWithLeftCapWidth:12 topCapHeight:0]; 
    UIImageView *backgroundImageView = [[UIImageView alloc] initWithFrame:sectionFrame]; 
    backgroundImageView.image = stretchableImage; 

    // Add it to the view for the header 
    UIView *sectionView = [[UIView alloc] initWithFrame:sectionFrame]; 
    sectionView.alpha = 0.9; 
    sectionView.backgroundColor = [UIColor clearColor]; 
    [sectionView addSubview:backgroundImageView]; 

Wreszcie stworzył wytwórnię i dodaje go jako podrzędny:

CGRect labelFrame = CGRectMake(10.0, 0.0, 290.0, height); 
    UILabel *sectionLabel = [[UILabel alloc] initWithFrame:labelFrame]; 
    sectionLabel.text = sectionTitle; 
    sectionLabel.numberOfLines = 0; 
    sectionLabel.font = [UIFont boldSystemFontOfSize:18.0]; 
    sectionLabel.textColor = [UIColor whiteColor]; 
    sectionLabel.shadowColor = [UIColor grayColor]; 
    sectionLabel.shadowOffset = CGSizeMake(0, 1); 
    sectionLabel.backgroundColor = [UIColor clearColor]; 
    [sectionView addSubview:sectionLabel]; 

    return sectionView; 
3

Dla Zmień kolor tła Tableview sekcji nagłówka Just One Linia rzeczy dodać TableView delegata willDisplayHeaderView:

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

    UITableViewHeaderFooterView *header = (UITableViewHeaderFooterView *)view; 
    **header.tintColor = [UIColor whiteColor];** 

} 
1

Objective-C:

[UIColor colorWithRed:232/255.0f green:233/255.0f blue:237/255.0f alpha:1.0f] 

SWIFT:

UIColor(red: 232/255, green: 233/255, blue: 237/255, alpha: 1) 
+0

Dotyczy systemu iOS 9 i nowszego –

Powiązane problemy