I'm stuck in titleview When i used Navigationitem.title then it show me in large title but title view is does not show please guys help me for this Thank You
:- 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;
First of all you are using button in large title, about that I've no idea.
But, when you use default title for large title, you need to enable following properties in AppDelegate's method:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[UINavigationBar appearance] setPrefersLargeTitles:true];
return YES;
}
Output:
This will enable large title for you all screen in default navigation bar.
I hope this will help you.
The iOS large title does not work with custom title views as you want.
If a navigationItem has both it's title and titleView properties set and the navigationBar has prefersLargeTitles set to YES you will get both a large title displayed in a second line while the provided titleView is show as usual at the top center of the navigation bar.
Long story short: this is not possible.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.