我在 app delegate 中修改了我的导航栏,如下所示:
NSDictionary *settings = @{
UITextAttributeFont : [UIFont fontWithName:@"impact" size:36.0],
UITextAttributeTextColor : [UIColor whiteColor],
UITextAttributeTextShadowColor : [UIColor clearColor],
UITextAttributeTextShadowOffset : [NSValue valueWithUIOffset:UIOffsetZero]};
[[UINavigationBar appearance] setTitleTextAttributes:settings];
但是对于较大的字体,字体会像这样缩小。 :
我尝试在我的 VC 的 viewWillAppear 中这样做:
UIView *newTitleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
[newTitleView setBackgroundColor:[UIColor blackColor]];
[self.navigationController.navigationBar addSubview:newTitleView];
然后我打算将标题居中对齐。但这似乎不对。我真正需要的只是删除标题标签顶部和底部的边距。我该怎么做。
最佳答案
试试这段代码,不要设置 setTitleTextAttributes
UILabel *titleView = (UILabel *)self.navigationItem.titleView;
if (!titleView) {
titleView = [[UILabel alloc] initWithFrame:CGRectZero];
titleView.backgroundColor = [UIColor clearColor];
titleView.font = [UIFont boldSystemFontOfSize:20.0];
titleView.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
titleView.textColor = [UIColor yellowColor]; // Change to desired color
self.navigationController.navigationItem.titleView = titleView;
[titleView release];
}
titleView.text = title;
[titleView sizeToFit];
关于ios - 删除 uinavigationbar 标题边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16536379/