Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - (void) viewDidLoad {
- [super viewDidLoad];
- // Create the search bar
- self.searchBar = [SearchBar new];
- // Create a new UIView as titleView (otherwise I'm receiving an error)
- self.navigationItem.titleView = [UIView new];
- // Add into view hierarchy and turn off auto constraints
- [self.navigationController.navigationBar addSubview:self.navigationItem.titleView];
- [self.navigationItem.titleView setTranslatesAutoresizingMaskIntoConstraints:NO];
- [self.navigationItem.titleView addSubview:self.searchBar.view];
- [self.searchBar.view setTranslatesAutoresizingMaskIntoConstraints:NO];
- // Set anchors for the wrapping view
- [self.navigationItem.titleView.widthAnchor constraintEqualToAnchor:self.navigationController.navigationBar.widthAnchor multiplier:1.0/3.0].active = YES;
- //[self.navigationItem.titleView.heightAnchor constraintEqualToConstant:50.0].active = YES;
- [self.navigationItem.titleView.topAnchor constraintEqualToAnchor:self.navigationController.navigationBar.topAnchor].active = YES;
- [self.navigationItem.titleView.centerXAnchor constraintEqualToAnchor:self.navigationController.navigationBar.centerXAnchor].active = YES;
- [self.navigationItem.titleView.bottomAnchor constraintEqualToAnchor:self.navigationController.navigationBar.bottomAnchor].active = YES;
- // Set anchors for the search bar
- [self.searchBar.view.widthAnchor constraintEqualToAnchor:self.navigationItem.titleView.widthAnchor multiplier:1.0].active = YES;
- //[self.navigationItem.titleView.heightAnchor constraintEqualToConstant:50.0].active = YES;
- [self.searchBar.view.topAnchor constraintEqualToAnchor:self.navigationItem.titleView.topAnchor].active = YES;
- [self.searchBar.view.bottomAnchor constraintEqualToAnchor:self.navigationItem.titleView.bottomAnchor].active = YES;
- //[self.searchBar.view.leftAnchor constraintEqualToAnchor:self.navigationItem.titleView.leftAnchor].active = YES;
- //[self.searchBar.view.rightAnchor constraintEqualToAnchor:self.navigationItem.titleView.rightAnchor].active = YES;
- [self.searchBar.view.centerXAnchor constraintEqualToAnchor:self.navigationItem.titleView.centerXAnchor].active = YES;
- }
Add Comment
Please, Sign In to add comment