相关疑难解决方法(0)

无法在导航栏的中心设置titleView,因为后退按钮

我正在使用图像视图在导航栏中显示图像.问题是由于后退按钮我无法正确设置它.我检查了相关问题,并且在我解决之前遇到了几乎相同的问题,但这次我不知道.

之前我用假条形按钮解决了这个问题,所以我尝试在右侧(和左侧)添加假条形按钮,但它没有帮助.

- (void) searchButtonNavBar {


    CGRect imageSizeDummy = CGRectMake(0, 0, 25,25);

    UIButton *dummy = [[UIButton alloc] initWithFrame:imageSizeDummy];

    UIBarButtonItem
    *searchBarButtonDummy =[[UIBarButtonItem alloc] initWithCustomView:dummy];
    self.navigationItem.rightBarButtonItem = searchBarButtonDummy;

}


- (void)setNavBarLogo {

    [self setNeedsStatusBarAppearanceUpdate];
    CGRect myImageS = CGRectMake(0, 0, 44, 44);
    UIImageView *logo = [[UIImageView alloc] initWithFrame:myImageS];
    [logo setImage:[UIImage imageNamed:@"color.png"]];
    logo.contentMode = UIViewContentModeScaleAspectFit;
    self.navigationItem.titleView = logo;
    [[UIBarButtonItem appearance] setTitlePositionAdjustment:UIOffsetMake(0.0f, 0.0f) forBarMetrics:UIBarMetricsDefault];

}
Run Code Online (Sandbox Code Playgroud)

我认为它应该工作得很好,因为在这种情况下titleView,同一侧有条形按钮.是否有任何解释为什么它可以使用以编程方式创建但不能与常用后退按钮一起使用的条形按钮?

objective-c uinavigationbar ios

48
推荐指数
5
解决办法
4万
查看次数

标签 统计

ios ×1

objective-c ×1

uinavigationbar ×1