Après avoir rencontré le même problème (comme d'autres) de l'étiquette qui se déplace lorsque nous insérons un bouton dans la navBar (dans mon cas, j'ai un spinner que je remplace par un bouton lorsque la date est chargée), les solutions ci-dessus n'ont pas fonctionné pour moi, alors voici ce qui a fonctionné et a gardé l'étiquette au même endroit tout le temps :
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
{
// this will appear as the title in the navigation bar
//CGRect frame = CGRectMake(0, 0, [self.title sizeWithFont:[UIFont boldSystemFontOfSize:20.0]].width, 44);
CGRect frame = CGRectMake(0, 0, 180, 44);
UILabel *label = [[[UILabel alloc] initWithFrame:frame] autorelease];
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont boldSystemFontOfSize:20.0];
label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
label.textAlignment = UITextAlignmentCenter;
label.textColor = [UIColor yellowColor];
self.navigationItem.titleView = label;
label.text = NSLocalizedString(@"Latest Questions", @"");
[label sizeToFit];
}
return self;