I am unable to set frame of UISearchBarTextField.... Should I create my own Search Bar or Is there a way to do the above?
Asked
Active
Viewed 7,413 times
0
-
http://stackoverflow.com/questions/556814/changing-the-size-of-the-uisearchbar-textfield look this – Sport Feb 03 '14 at 06:28
-
at least share some codes,what you tried? – Wali Haider Feb 03 '14 at 06:30
-
UITextField *txfSearchField = [searchBar valueForKey:@"_searchField"]; [txfSearchField setFrame:CGRectMake(20, 50, 200, 30)]; – sargeras Feb 03 '14 at 06:38
-
http://stackoverflow.com/questions/18993773/uitextfield-not-working-as-subview-to-uisearchbar-in-ios-7 .... try this link for getting uitextfield of search bar.. – RAJA Feb 03 '14 at 06:39
-
I will look into those links – sargeras Feb 03 '14 at 06:43
2 Answers
2
in iOS 7 to access Text Field you have to reiterate on level more. Change your code like this
for (UIView *subView in self.searchBar.subViews){
for (UIView *2ndLeveSubView in subView.subViews){
if ([2ndLeveSubView isKindOfClass:[UITextField class]])
{
searchBarTextField = (UITextField *)2ndLeveSubView;
break;
}
}
}
But best way to clear backgournd of UISearchBar and setting searchbar icon in text field is:
[searchBar setBackgroundImage:[[UIImage alloc] init] ];//if you want to remove background of uisearchbar
UIImage *image = [UIImage imageNamed: @"search_icon.png"];
[searchBar setImage:image forSearchBarIcon:UISearchBarIconSearch state:UIControlStateNormal];

kagmanoj
- 5,038
- 5
- 19
- 21
-5
Have you try this.
[searchBarObj setFrame:CGRectMake(44, 0, 320 - 44, 43)];

Ayaz
- 1,398
- 15
- 29
-
-
i am not understand what exactly you want. provide some more description. – Ayaz Feb 03 '14 at 07:35