2012-01-04 101 views
0

我有一個UILabel我試圖將半透明漸變作爲顏色應用於。舉例來說,在我的UILabel子類我試圖設置漸變顏色是這樣的:UILabel帶有圖層陰影的文字顏色透明度?

self.textColor = [UIColor colorWithPatternImage:someTransparentGradient]; 

雖然這個瞎搞,不過,我發現,UILabel似乎並沒有能夠與透明畫當圖層陰影已到位。我試圖設置文本顏色清除:

self.textColor = [UIColor clearColor]; 

但文本結束爲白色。想法?

如果您將文本顏色設置爲清除,然後將圖層陰影應用於文本視圖,則可以自己複製問題。

+0

你在哪裏設置了textColor?即,'self.textColor = [UIColor clearColor];' – Ilanchezhian 2012-01-04 06:34:56

+0

我在我的'UILabel'子類中將它設置爲一個自定義方法。 – 2012-01-04 06:38:40

+0

你有'不透明'設置爲'YES'嗎? – 2012-01-20 20:52:34

回答

1

我通常不會接受我自己的答案,但在這種情況下,我必須。這似乎是一個錯誤。每當將圖層陰影應用於UILabel時,不再支持文本透明度。我將提交一份雷達。

3

如果您通過nib創建了UILabel,並且在initWithFrame中設置了textColor,您將無法獲得所需的結果。

UILabel子類中,編寫initWithCoder並設置顏色。

-(id)initWithCoder:(NSCoder *)aDecoder 
{ 
    self = [super initWithCoder:aDecoder]; 
    if (self) { 
     // Initialization code 
     self.textColor = [UIColor clearColor]; 
    } 
    return self; 
} 

編輯

看,這是屏幕截圖用默認值(灰色)的背景。

enter image description here

這是白色背景

enter image description here

截圖請下載sample application和嘗試。

+0

我通過nib文件創建了'UILabel',但是我沒有重寫'initWithFrame',因爲如果它是從一個nib實例化的,那麼就不會調用它。我有一個自定義初始化程序,它在標準的'initWithCoder:'之後被調用。但是如果你真的用'[UIColor clearColor]'嘗試你的方法,你會發現文本仍然是白色的。 – 2012-01-04 06:40:51

+0

我嘗試過'clearColor'。如果它是clearColor,那麼文本是不可見的。所以確保你在'initWithCoder'裏設置顏色 – Ilanchezhian 2012-01-04 06:56:06

+0

我已經上傳了測試應用程序。請下載並嘗試。 – Ilanchezhian 2012-01-04 07:33:22