我的客户无法阅读iPhone的默认字体,字体太小了。我有一个带有导航栏的应用程序,我需要使其中的所有内容变大,例如字体大小。
IB似乎不允许这样做...有什么帮助吗?
非常感谢!
我的客户无法阅读iPhone的默认字体,字体太小了。我有一个带有导航栏的应用程序,我需要使其中的所有内容变大,例如字体大小。
IB似乎不允许这样做...有什么帮助吗?
非常感谢!
这里的许多答案都是错误或不完整的,因此我想在这里添加我的答案,希望它能启发一些人。
首先,改变导航栏的高度没有任何问题。评论中说它不被允许或违反了指南的人只是误解了这些指南。
自iOS 5以来,调整或更改UINavigationController内使用的默认导航栏的能力已成为SDK的一部分。
- (instancetype)initWithNavigationBarClass:(Class)navigationBarClass toolbarClass:(Class)toolbarClass NS_AVAILABLE_IOS(5_0);
改变状态栏高度的最简单方法是在初始化导航控制器时使用此方法,传入您的自定义UINavigationBar子类。
TestViewController *t = [[TestViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithNavigationBarClass:[MyNavigationBar class] toolbarClass:[UIToolbar class]];
[nav setViewControllers:@[t]];
[self.window setRootViewController:nav];
[self.window makeKeyAndVisible];
一个自定义的UINavigationBar类的示例可能如下:
@interface MyNavigationBar : UINavigationBar
@end
@implementation MyNavigationBar
- (CGSize)sizeThatFits:(CGSize)size
{
CGSize s = [super sizeThatFits:size];
s.height = 90; // Or some other height
return s;
}
@end
UIViewController
的viewDidLoad
方法中执行以下操作:UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
[titleLabel setBackgroundColor:[UIColor clearColor]];
// here's where you can customize the font size
[titleLabel setFont:[UIFont boldSystemFontOfSize:18.0]];
[titleLabel setTextColor:[UIColor whiteColor]];
[titleLabel setText:self.title];
[titleLabel sizeToFit];
[titleLabel setCenter:[self.navigationItem.titleView center]];
[self.navigationItem setTitleView:titleLabel];
[titleLabel release];
#import <UIKit/UIKit.h>
@interface ASNavigationBar : UINavigationBar
@property (nonatomic , retain) UIImage *backgroundImage;
@end
实施:
#import "ASNavigationBar.h"
@implementation ASNavigationBar
@synthesize backgroundImage = _backgroundImage;
-(void) setBackgroundImage:(UIImage *)backgroundImage
{
if (_backgroundImage != backgroundImage)
{
[_backgroundImage release];
_backgroundImage = [backgroundImage retain];
[self setNeedsDisplay];
}
}
-(void) drawRect:(CGRect)rect
{
// This is how the custom BG image is actually drawn
[self.backgroundImage drawInRect:rect];
}
- (CGSize)sizeThatFits:(CGSize)size
{
// This is how you set the custom size of your UINavigationBar
CGRect frame = [UIScreen mainScreen].applicationFrame;
CGSize newSize = CGSizeMake(frame.size.width , self.backgroundImage.size.height);
return newSize;
}
@end
补充Skela的答案:
如果您在Storyboard中启动导航控制器,您可以在Storyboard中更改UINavigationBar的类为您的自定义导航栏。
然后在类中实现更改高度
@interface MyNavigationBar : UINavigationBar
@end
@implementation SwitchAssessmentNavigationBar
- (CGSize)sizeThatFits:(CGSize)size
{
CGSize s = [super sizeThatFits:size];
s.height = 200; // Or some other height
return s;
}
@end