Mon application a splitview et il est activé uniquement en mode paysage. Dans masterview j'ai tableview et dans la dernière section j'ai un bouton personnalisé. Le problème est que la largeur du bouton reste dans le potrait au lieu d'utiliser l'orientation du périphérique. J'ai essayé de jouer avec setAutoresizingMask sur le bouton et la vue, mais ça ne marche pas non plus.iPad, redimensionner bouton personnalisé dans viewForHeaderInSection
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger) sectionNum {
if (sectionNum == 4) {
CGRect frameSize;
if (UIInterfaceOrientationIsLandscape([[UIDevice currentDevice] orientation])) {
frameSize = CGRectMake(45.0, 0.0, 600.0, 44.0);
} else {
frameSize = CGRectMake(45.0, 0.0, 680.0, 44.0);
}
UIView *btnView = [[[UIView alloc] initWithFrame:frameSize] autorelease];
// button
UIButton* btnFind = [UIButton buttonWithType:UIButtonTypeCustom];
[btnFind setBackgroundImage:[[UIImage imageNamed:@"buttonblue.png"] stretchableImageWithLeftCapWidth:14.0 topCapHeight:0.0] forState:UIControlStateNormal];
[btnFind setBackgroundImage:[[UIImage imageNamed:@"buttonred.png"] stretchableImageWithLeftCapWidth:14.0 topCapHeight:0.0] forState:UIControlStateHighlighted];
btnFind.frame = frameSize;
btnFind.tag = 1;
[btnFind setTitle:@"Find" forState:UIControlStateNormal];
[btnFind addTarget:self action:@selector(doSearchDoc:) forControlEvents:UIControlEventTouchUpInside];
//[btnFind setAutoresizingMask:UIViewAutoresizingFlexibleRightMargin];
//[btnView setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
[btnView addSubview:btnFind];
return btnView;
}
return nil;
}
Quelqu'un peut-il s'il vous plaît laissez-moi savoir comment résoudre ce problème.
Merci.
merci beaucoup, cela fonctionne bien. – Inoel
dans mon cas cela fonctionne mieux: j'ai modifié votre code et remplacer .reloadData par .reloadSections: [NSIndexSet indexSetWithIndex: btnSectionIndex] withRowAnimation: NO]; – Inoel