Skip to content

Instantly share code, notes, and snippets.

@ifournight
Last active October 3, 2019 23:05
Show Gist options
  • Save ifournight/5894520 to your computer and use it in GitHub Desktop.
Save ifournight/5894520 to your computer and use it in GitHub Desktop.
UISearchbar Text Aligment
self.searchbar = [[UISearchBar alloc] initWithFrame:CGRectMake(5.0, 0.0, 310.0, 44.0)];
self.searchbar.autocorrectionType = UITextAutocorrectionTypeNo;
self.searchbar.showsCancelButton = YES;
self.searchbar.spellCheckingType = UITextSpellCheckingTypeNo;
[self.searchbar setImage:[UIImage imageNamed:@"SearchBarIcon-Search.png"]
forSearchBarIcon:UISearchBarIconSearch
state:UIControlStateNormal];
[self.searchbar setImage:[UIImage imageNamed:@"SearchBarIcon-Clear.png"]
forSearchBarIcon:UISearchBarIconClear
state:UIControlStateNormal];
[self.searchbar setSearchFieldBackgroundImage:[[UIImage imageNamed:@"SearchField.png"] resizableImageWithCapInsets:kSearchFieldImageInsets]
forState:UIControlStateNormal];
self.searchbar.backgroundImage = nil;
self.searchbar.backgroundColor = [UIColor clearColor];
for (UIView *subview in self.searchbar.subviews) {
if ([subview isKindOfClass:[UITextField class]]) {
[(UITextField *)subview setTextColor:[UIColor colorWithRed:0.68 green:0.68 blue:0.68 alpha:1.0]];
break;
UITextField *text = (UITextField*)subView;
text.textAlignment = UITextAlignmentRight;
text.rightViewMode = UITextFieldViewModeAlways;
}
}
@nikmis
Copy link

nikmis commented Aug 12, 2015

Does not work in iOS 8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment