2009-12-28 17 views

回答

0

看來這不支持iPhone OS 3.0內。我只是用UIImageView的透明UITextField作爲背景。我相信這是官方iPhone短信文本輸入的工作原理。

0

UITextBorderStyleRoundedRect怎麼樣?

textField.borderStyle = UITextBorderStyleRoundedRect; 

您也可以直接使用UISearchBar並自己手動處理文本。

+0

UITextBorderStyleRoundedRect不會像帶有SearchBar TextField的圓角出現。 – Luke 2010-01-02 06:09:15

+0

在這種情況下,您仍然可以使用UISearchBar,它的行爲非常像UITextField,並以您希望的任何方式處理文本輸入。 – 2010-01-02 15:26:54

6

如果您願意,您可以從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的第二個子視圖是實際的文本字段;儘管如此,在未來的任何操作系統發佈中都會有所改變

這會將PNG保存到應用程序的文檔目錄中,您可以在該目錄中抓取它並將其放入項目中,並將其用作文本字段的背景。可伸縮圖像的左和頂帽寬度是15個像素。

相關問題