我正在开发一个iPhone应用程序,我正在继承UINavigationBar来创建我的自定义导航栏.我想要的是一个更高的导航栏,以及一个位于titleView中的UISearchBar.我想在导航栏中留出更多空间,因为我想在搜索栏下面的底部放置一个分段控件.这是我到目前为止所做的:
// Custom navigation bar implementation
const CGFloat BUNavigationBarHeightIncrease = 38.0f;
@implementation BUNavigationBar
// This resizes the navigation bar height
- (CGSize)sizeThatFits:(CGSize)size {
CGSize amendedSize = [super sizeThatFits:size];
amendedSize.height += BUNavigationBarHeightIncrease;
return amendedSize;
}
// This repositions the navigation buttons
- (void)layoutSubviews {
[super layoutSubviews];
NSArray *classNamesToReposition = @[@"UINavigationButton"];
for (UIView *view in [self subviews]) {
if ([classNamesToReposition containsObject:NSStringFromClass([view class])]) {
CGRect frame = [view frame];
frame.origin.y -= BUNavigationBarHeightIncrease;
[view setFrame:frame];
}
}
}
@end
Run Code Online (Sandbox Code Playgroud)
我将此导航栏分配给导航控制器,如下所示:
- (IBAction)searchButton:(id)sender {
SearchViewController …Run Code Online (Sandbox Code Playgroud)