Guest User

Untitled

a guest
Jul 18th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. - (void) viewDidLoad {
  2. [super viewDidLoad];
  3.  
  4. // Create the search bar
  5. self.searchBar = [SearchBar new];
  6.  
  7. // Create a new UIView as titleView (otherwise I'm receiving an error)
  8. self.navigationItem.titleView = [UIView new];
  9.  
  10. // Add into view hierarchy and turn off auto constraints
  11. [self.navigationController.navigationBar addSubview:self.navigationItem.titleView];
  12. [self.navigationItem.titleView setTranslatesAutoresizingMaskIntoConstraints:NO];
  13. [self.navigationItem.titleView addSubview:self.searchBar.view];
  14. [self.searchBar.view setTranslatesAutoresizingMaskIntoConstraints:NO];
  15.  
  16. // Set anchors for the wrapping view
  17. [self.navigationItem.titleView.widthAnchor constraintEqualToAnchor:self.navigationController.navigationBar.widthAnchor multiplier:1.0/3.0].active = YES;
  18. //[self.navigationItem.titleView.heightAnchor constraintEqualToConstant:50.0].active = YES;
  19. [self.navigationItem.titleView.topAnchor constraintEqualToAnchor:self.navigationController.navigationBar.topAnchor].active = YES;
  20. [self.navigationItem.titleView.centerXAnchor constraintEqualToAnchor:self.navigationController.navigationBar.centerXAnchor].active = YES;
  21. [self.navigationItem.titleView.bottomAnchor constraintEqualToAnchor:self.navigationController.navigationBar.bottomAnchor].active = YES;
  22.  
  23. // Set anchors for the search bar
  24. [self.searchBar.view.widthAnchor constraintEqualToAnchor:self.navigationItem.titleView.widthAnchor multiplier:1.0].active = YES;
  25. //[self.navigationItem.titleView.heightAnchor constraintEqualToConstant:50.0].active = YES;
  26. [self.searchBar.view.topAnchor constraintEqualToAnchor:self.navigationItem.titleView.topAnchor].active = YES;
  27. [self.searchBar.view.bottomAnchor constraintEqualToAnchor:self.navigationItem.titleView.bottomAnchor].active = YES;
  28. //[self.searchBar.view.leftAnchor constraintEqualToAnchor:self.navigationItem.titleView.leftAnchor].active = YES;
  29. //[self.searchBar.view.rightAnchor constraintEqualToAnchor:self.navigationItem.titleView.rightAnchor].active = YES;
  30. [self.searchBar.view.centerXAnchor constraintEqualToAnchor:self.navigationItem.titleView.centerXAnchor].active = YES;
  31. }
Add Comment
Please, Sign In to add comment