Hec*_*ret 5 iphone uinavigationbar
我的客户端无法读取iPhone的默认字体,尺寸太小.我有一个带导航栏的应用程序,我需要将其中的所有内容放大,例如,字体的大小.
IB似乎不允许这样......任何帮助?
非常感谢!
And*_*sov 13
更新:今天(2012年)有一个更大的自定义用户界面的趋势,所以我想说下面的答案太苛刻了.但是,仍然没有支持自定义高度的方法,但是你当然可以从UINavigationBar派生并覆盖一些大小调整方法.这可能不会让你被拒绝(虽然它仍然是一个灰色区域,只是苹果今天可能会忽视的东西).
获得所需大小后,可以使用iOS 5自定义API添加自定义背景图像(请参阅WWDC 2011会话114 - 自定义UIKit控件的外观).
2009年的原始答案:
这通常是不可能的.
更重要的是,我认为使导航栏更高是违反Apple人机界面指南的,因此您的应用程序可能会被App Store拒绝.在继续操作之前,请确保您的客户了解此风险.
(指出拒绝风险通常是说服客户做出无意义决策的好方法.)
Ske*_*ela 11
这里的许多答案都是不正确或不完整的,所以我想在这里添加我的答案,希望它可以启发一些.
首先,更改导航栏的高度没有任何问题.人们评论说不允许,或违反准则只是误解了这些指导方针.
自iOS 5以来,调整或更改UINavigationController中使用的默认导航栏的能力已成为SDK的一部分.
- (instancetype)initWithNavigationBarClass:(Class)navigationBarClass toolbarClass:(Class)toolbarClass NS_AVAILABLE_IOS(5_0);
Run Code Online (Sandbox Code Playgroud)
更改状态栏高度的最简单方法是在初始化导航控制器时使用此方法,并传入自定义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];
Run Code Online (Sandbox Code Playgroud)
这种自定义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
Run Code Online (Sandbox Code Playgroud)
如果你决定只改变导航栏中的字体大小,你可以这样做(通常在你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];
Run Code Online (Sandbox Code Playgroud)
通过子类化,您可以实现并仍然支持iOS 3+:
#import <UIKit/UIKit.h>
@interface ASNavigationBar : UINavigationBar
@property (nonatomic , retain) UIImage *backgroundImage;
@end
Run Code Online (Sandbox Code Playgroud)
并实施:
#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
Run Code Online (Sandbox Code Playgroud)