How to change a UITextField to look like a search box?

I would like to change the default iPhone UITextField so that it looks exactly like the search text box in the UISearchBar. You can see an example of this for the SMS text input field in the iPhone Messages application.

I do not think that UITextField has a style property that will meet this requirement. Any ideas?

+3
source share
3 answers

This seems to be not supported on iPhone OS 3.0. I just used a transparent UITextField with a UIImageView as the background. I believe that this is how the official iPhone iPhone recording works.

0
source

, uisearch , UITextField. , . , :

UIImage *img = [[[self.searchBar subviews] objectAtIndex:1] background];
NSData *imgdata = UIImagePNGRepresentation(img);

NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectoryPath = [searchPaths objectAtIndex: 0];

[imgdata writeToFile:[documentsDirectoryPath stringByAppendingPathComponent:@"searchbarbg.png"] atomically:YES];

uisearchbar - ; os.

PNG , . 15 .

+6

UITextBorderStyleRoundedRect?

textField.borderStyle = UITextBorderStyleRoundedRect;

UISearchBar .

0
source

Source: https://habr.com/ru/post/1726695/


All Articles