2012-05-31 33 views
3

我有一個UILabel,這個標籤有一個填充的backgroundcolor(這是我的textView頭)。我想啓用一個陰影,使這個黑暗的陰影落在textview上。如何在UILabel上設置陰影背景?

我已經在我對標籤文本實施陰影的時候了。

 descriptionLabel.layer.shadowColor = [[UIColor blackColor] CGColor]; 
     descriptionLabel.layer.shadowOffset = CGSizeMake(4.0f, 0.0f); 
     descriptionLabel.layer.shadowOpacity = 1.0f; 
     descriptionLabel.layer.shadowRadius = 1.0f; 

但是我希望陰影在標籤的完整框架之下(所以不是文本)。

回答

2

您可以更改陰影路徑是明確的矩形,而不是使用圖層內容:

CGPathRef shadowPath = CGPathCreateWithRect(descriptionLabel.bounds, NULL); 
descriptionLabel.layer.shadowPath = shadowPath; 
CGPathRelease(shadowPath); 

這也是添加陰影的視圖時提高渲染性能一個很常見的技術。固定矩形陰影的繪製速度比基於圖層內容的繪製要快很多倍。

+0

不錯的提示,謝謝! – BarryK88