title: Adding UISearchBar in UINavigationBar with constraints
body: <p>All,</p>
  
  <p>I want to add UISearchBar to UINavigationbar, I dont dont want to use UISearchController, Just UISearchbar programmatically and it must work in landscape as well. </p>
  
  <p>I tried it is working well in Portrait well, but in Landscape, i have issues in iPhone X  width. Can we use Constraints. </p>
  
  <p>Below is the code</p>
  
  <p><a href="https://i.stack.imgur.com/dvWBS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dvWBS.png" alt="enter image description here"></a></p>
  
  <pre><code> CGFloat width = [UIScreen mainScreen].bounds.size.width;
      search = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, width - 2 * 44 - 2 * 15, 44)];
      search.delegate = self; //    search.tintColor = [UIColor redColor];
      search.searchBarStyle = UISearchBarStyleMinimal;
      search.placeholder = @"Search";
      search.translucent = NO;
      search.opaque = NO;
      search.showsCancelButton = NO;
      [search setBackgroundImage:[[UIImage alloc] init]];
  
      //customize textfield inside UISearchBar
      @try {
          for (id object in [[[search subviews] firstObject] subviews])
          {
              if (object &amp;&amp; [object isKindOfClass:[UITextField class]])
              {
                  UITextField *textFieldObject = (UITextField *)object;
                  textFieldObject.backgroundColor = [UIColor whiteColor];
                  textFieldObject.borderStyle = UITextBorderStyleRoundedRect;
                  textFieldObject.layer.borderColor = (__bridge CGColorRef _Nullable)([brandingObj getValueForKey:navBarTitleColor]);
                  textFieldObject.layer.borderWidth = 1.0;
                  break;
              }
          }
      }
      @catch (NSException *exception) {
          NSLog(@"Error while customizing UISearchBar");
      }
      @finally {
  
      }
  </code></pre>