小编gde*_*ont的帖子

UISearchBar在自定义NavigationBar中

我正在开发一个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)

uinavigationbar uisearchbar ios

2
推荐指数
1
解决办法
605
查看次数

标签 统计

ios ×1

uinavigationbar ×1

uisearchbar ×1