0

I am using a search bar (UISearchBar) in my app and I want to override the editingRectForBounds and textRectForBounds method.

How would I be able to do this? Please help.

Moin Shirazi
  • 4,372
  • 2
  • 26
  • 38
Vignesh PT
  • 624
  • 12
  • 28
  • What do you mean? Just create a subclass that inherits from UISearchBar? – Vincent Sit Mar 13 '15 at 13:51
  • @Vincent But `editingRectForBounds` and `textRectForBounds` are overriding methods for `UITextField` and not for `UISearchBar`, right? Anyways, I've tried that and it didn't work. – Vignesh PT Mar 14 '15 at 14:33

2 Answers2

0

If your intention is to restrict size of text field, this could be useful 1.Create a subclass of UISearchBar
2.Include this code in the drawRect: method.

UITextView * textField = [self.subviews objectAtIndex:0]; textField.frame = CGRectMake(5, 6, (310 - kRightSideMargin), 31);

[super drawRect:rect]; changing-the-size-of-the-uisearchbar-textfield

Community
  • 1
  • 1
vignesh
  • 994
  • 10
  • 12
-1

Create a subclass of UITextField

eg. @interface DemoTextField : UITextField

and simply override your methods in implementation (.m) file

Sanket
  • 1