/ / UIAppearance verwenden, um die Etikettenhöhe zu ändern - iphone, object-c, ios, uinavigationbar, ios5

Verwenden von UIAppearance zum Ändern der Etikettenhöhe - iphone, object-c, ios, uinavigationbar, ios5

Gibt es eine Möglichkeit, UIAppearance zu verwenden, um die Höhe eines Etiketts in einer UINavigationBar zu ändern. Hier ist der Code und ein Bild von dem, was los ist, damit Sie verstehen können, was das Problem ist.

[[UINavigationBar appearance] setTitleVerticalPositionAdjustment:-5.0 forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setTitleVerticalPositionAdjustment:-5.0 forBarMetrics:UIBarMetricsLandscapePhone];

NSDictionary *textAttributes =  [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:[UIFont fontWithName:@"MarketingScript" size:34.0], nil]
forKeys:[NSArray arrayWithObjects:UITextAttributeFont, nil]];

Bildbeschreibung hier eingeben

Antworten:

0 für die Antwort № 1

Wahrscheinlich können Sie den UIA-Auftritt für UILabel in UINavigationBar erhalten.


0 für die Antwort № 2

Am Ende habe ich das Problem gelöst, indem ich eine benutzerdefinierte UIView erstellt habe:

+(NavigationBarTitleLabel *)titleLabelWithTitle:(NSString *)title {
// this will appear as the title in the navigation bar
NavigationBarTitleLabel *labelWrapper = [[NavigationBarTitleLabel alloc] initWithFrame:CGRectMake(0, 0, 200, 34)];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 8, 200, 32)];

label.font            = [UIFont fontWithName:@"MarketingScript" size:28.0];
label.text            = title;
label.textColor       = XHEXCOLOR(0XFFFFFF);
label.textAlignment   = UITextAlignmentCenter;
label.backgroundColor = [UIColor clearColor];
label.layer.shadowColor = [UIColor blackColor].CGColor;
label.layer.shadowRadius = 2;
[labelWrapper addSubview:label];
[labelWrapper sizeToFit];

return labelWrapper;
}

und dann die titleView-Eigenschaft im navigationItem einstellen:

self.navigationItem.titleView = [NavigationBarTitleLabel titleLabelWithTitle:self.title];