Last active
October 3, 2019 23:05
-
-
Save ifournight/5894520 to your computer and use it in GitHub Desktop.
UISearchbar Text Aligment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Does not work in iOS 8