2012-01-02 39 views
0

我遇到了一個我一直在研究幾個小時無濟於事的問題。我在我的應用程序中使用了自定義背景(使用Xcode 4.2)以及一些UITextFields。我想知道是否有辦法讓它們在啓動時融入背景,在點擊時變爲活動狀態,然後在編輯完成後顯示文本時融入背景。如何在編輯後將UITextField混合到背景中?

謝謝。

+0

你是什麼意思混合?你有什麼嘗試? – Sarah 2012-01-02 06:56:50

+0

我將UITextField的背景圖像設置爲IB中的當前背景,但這似乎沒有什麼區別。 – John 2012-01-02 06:58:02

+0

你的意思是,直到你點擊文本框,它應該是不可見的文本框,一旦點擊,它會顯示鍵盤。對? – Sarah 2012-01-02 06:59:23

回答

3

你爲什麼不改變邊界風格的uitextfield

1

將文本字段的alpha值設置爲1(對於活動模式)和0.25(對於混合模式)。

[self.textField setAlpha:] 
2

爲此,你應該做以下事情

1)清除文本字段背景

[myTextField setBackgroundColor:[UIColor clearColor]]; 

2)使用的UITextField委託方法如下

你可以使用的東西如下

//使清除背景當你有開始在textField中編輯。

- (void)textFieldDidBeginEditing:(UITextField *)textField 
{ 

//set here desired colour 

//or do here whatever you want 

[myTextField setBackgroundColor:[UIColor greyColour]]; 

} 

//明確的背景,當你點擊完成按鍵鍵盤的

- (BOOL)textFieldShouldReturn:(UITextField *)theTextField { 

    [myTextField setBackgroundColor:[UIColor clearColor]]; 

    [myTextField resignFirstResponder]; 

    return YES; 
} 

//使背景清晰當您結束鍵入

- (void)textFieldDidEndEditing:(UITextField *)textField{ 

    [myTextField setBackgroundColor:[UIColor clearColor]]; 
}