NavigationController NavigationBar TitleView 在 iOS Objective-C 中的导航栏大标题中不起作用

NavigationController NavigationBar TitleView is Not Working in Navigation Bar Large Title in iOS Objective-C

我卡在标题视图中 当我使用 Navigationitem.title 然后它以大标题显示但标题视图不显示 请大家帮助我 谢谢

:- searchBar Configure Code :-
      self.searchControllerInvoice = [[UISearchController alloc] initWithSearchResultsController:nil];
         self.searchControllerInvoice.searchResultsUpdater = self;
         self.searchControllerInvoice.delegate = self;

:- Navigation And TitleBUtton :-
                CGFloat maxTitleWidth = self.navigationController.navigationBar.frame.size.width;
            CGSize requestedTitleSize = [selectedName sizeWithAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:17]}];
            CGFloat titleWidth = MIN(maxTitleWidth-130, requestedTitleSize.width);

            if(!TitleButton)
            {
                TitleButton = [UIButton buttonWithType:UIButtonTypeSystem];
                [TitleButton setFrame:CGRectMake(0, 0, titleWidth , 22)];
            }

            [TitleButton.titleLabel setFont:[UIFont systemFontOfSize:17]];

            TitleButton.titleLabel.adjustsFontSizeToFitWidth = YES;
            TitleButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
            [TitleButton setTitle:selectedName forState:UIControlStateNormal];
            [TitleButton setImage:image forState:UIControlStateNormal];
            [TitleButton addTarget:self action:@selector(titleButtonClicked:) forControlEvents:UIControlEventTouchUpInside];

            TitleButton.semanticContentAttribute = UISemanticContentAttributeForceRightToLeft;
            TitleButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;

             if (@available(iOS 11.0, *)) {
                  self.navigationItem.searchController = self.searchControllerInvoice;
        //          [self.navigationItem.searchController.searchBar setBackgroundColor:UIColor.redColor];
             } else {
                  self.getInvoiceTable.tableHeaderView = self.searchControllerInvoice.searchBar;
             }

             self.navigationItem.titleView=TitleButton;

首先,您使用的是大标题按钮,对此我一无所知。

但是,当您使用大标题的默认标题时,您需要在 AppDelegate 的方法中启用以下属性:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    [[UINavigationBar appearance] setPrefersLargeTitles:true];

    return YES;
}

输出:

这将为您在默认导航栏中的所有屏幕启用大标题。

希望对您有所帮助。

iOS 大标题不适用于您想要的自定义标题视图。

如果 navigationItem 同时设置了它的 title 和 titleView 属性,并且 navigationBar 将 prefersLargeTitles 设置为 YES,那么您将在第二行中显示一个大标题,而提供的 titleView 照常显示在顶部中心导航栏.

长话短说:这是不可能的。