95 votes

Comment modifier la hauteur de l'en-tête d'un UITableView groupé ?

Je sais comment modifier la hauteur des en-têtes de section dans la vue tableau. Mais je ne trouve pas de solution pour modifier l'espacement par défaut avant la première section.

Actuellement, j'ai ce code :

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 0){
        return 0;
    }
    return 10;
}

enter image description here

0voto

Jasper Pol Points 1104

Exemple de viewForHeaderInSection :

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 118)];
view.backgroundColor = COLOR_DEFAULT;

NSString* key = [self.tableKeys objectAtIndex:section];
NSArray *result = (NSArray*)[self.filteredTableData objectForKey:key];
SZTicketsResult *ticketResult = [result objectAtIndex:0];

UIView *smallColoredView = [[UIView alloc] initWithFrame:CGRectMake(0, 5, 320, 3)];
smallColoredView.backgroundColor = COLOR_DEFAULT_KOSTKY;
[view addSubview:smallColoredView];

UIView *topBackgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 8, 320, 40)];
topBackgroundView.backgroundColor = [UIColor colorWithRed:255.0/255.0 green:248.0/255.0 blue:174.0/255.0 alpha:1];
[view addSubview:topBackgroundView];

UILabel *totalWinnings = [[UILabel alloc] initWithFrame:CGRectMake(10, 8, 300, 40)];
totalWinnings.text = ticketResult.message;
totalWinnings.minimumFontSize = 10.0f;
totalWinnings.numberOfLines = 0;
totalWinnings.backgroundColor = [UIColor clearColor];
totalWinnings.font = [UIFont boldSystemFontOfSize:15.0f];
[view addSubview:totalWinnings];

UIView *bottomBackgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 55, 320, 58)];
bottomBackgroundView.backgroundColor = [UIColor colorWithRed:255.0/255.0 green:248.0/255.0 blue:174.0/255.0 alpha:1];
[view addSubview:bottomBackgroundView];

UILabel *numberOfDraw = [[UILabel alloc] initWithFrame:CGRectMake(10, 55, 290, 58)];
numberOfDraw.text = [NSString stringWithFormat:@"sometext %@",[ticketResult.title lowercaseString]];;
numberOfDraw.minimumFontSize = 10.0f;
numberOfDraw.numberOfLines = 0;
numberOfDraw.backgroundColor = [UIColor clearColor];
numberOfDraw.font = [UIFont boldSystemFontOfSize:15.0f];
[view addSubview:numberOfDraw];

return view;

Prograide.com

Prograide est une communauté de développeurs qui cherche à élargir la connaissance de la programmation au-delà de l'anglais.
Pour cela nous avons les plus grands doutes résolus en français et vous pouvez aussi poser vos propres questions ou résoudre celles des autres.

Powered by:

X