2012-06-23 326 views
0

我有一個包含文本字段的應用程序。文本字段的背景透明度

有沒有辦法在代碼中更改此文本字段的背景透明度?

+0

你想要什麼背景顏色與清晰的顏色? –

+0

是的確切我不想任何背景顏色 – Alippo

+0

然後使用此代碼我粘貼代碼與ClearColor波紋見下面我clearColor的代碼:) –

回答

1

只要將波紋管代碼白色背景

[yourTextField setBackgroundColor:[UIColor whiteColor]]; 

,或者如果想清除的顏色,然後婁代碼

[yourTextField setBackgroundColor:[UIColor clearColor]]; 

這麼簡單

:)

1

使用Custom UITextField

UITextField *yourTextField= [[UITextField alloc] initWithFrame:frame]; 
yourTextField.borderStyle = UITextBorderStyleNone; 
[yourTextField setBackgroundColor:[UIColor clearColor]]; 
+0

參考[自定義UITextField](http://www.roseindia.net/answers/viewqa/Mobile-Applications/15639-UITextField-Programmatically-iPhone.html) – Hector

2

是的,你可以做到這一點。

您可以通過設置透明度來設置透明度。您可以使用數字色彩表(它是Mac中的內置應用程序)來拍攝彩色代碼。

如果設置了alpha 1,那麼將不會有透明度。根據您的需要設置透明度(將alpha設置爲小於1)。

試試這個:

textfield.backgroundColor=[[UIColor colorWithRed:208.0/255.0 green:15.0/255.0 blue:202.0/255.0 alpha:0.6] CGColor]; 
+0

嘿朋友,如果你想背景透明或清除setBackground的顏色clearColor只有一個簡單的線代碼夥計...喜歡.. [yourTextField setBackgroundColor:[UIColor clearColor]]; :) –

+1

@ParasJoshi您對使用clearColor的簡單性是正確的,但這仍然是一個很好的例子。這個答案是提問者基本顏色操作的一個很好的總結。爲你們兩個+1! –