2010-12-09 57 views
4

我已經能夠在我的視圖中爲許多UI對象添加陰影,包括在UIImageView中很好地放置一些自定義繪圖的陰影。然而,當應用於UITextView時,相同的代碼不會產生任何東西:基於石英的陰影不適用於我UITextView

[desc.layer setShadowColor:[[UIColor blackColor] CGColor]]; 
[desc.layer setShadowRadius:2.0f]; 
[desc.layer setShadowOffset:CGSizeMake(1, 1)]; 
[desc.layer setShadowOpacity:0.8f]; 

這是我失蹤的東西嗎?我希望使用石英來添加邊框和陰影。

//Border. 
/* 
[desc.layer setBackgroundColor:[[KookaSettings sharedInstance].cellBackgroundColorD CGColor]]; 
[desc.layer setBorderColor: [[UIColor blackColor] CGColor]]; 
[desc.layer setBorderWidth:1.0f]; 
[desc.layer setCornerRadius:8.0f]; 
*/ 

回答

10

我知道,如果該視圖有clipsToBounds集的陰影不起作用:在評價時,邊境代碼確實工作。也許UITextView有默認設置?

+0

謝謝! \t [desc setClipsToBounds:NO]; – Diziet 2010-12-09 18:41:13

1

您需要將clipsToBounds設置爲NO作爲陰影,但缺點是如果您的文本比視圖的可見區域更長,並且需要滾動它,那麼它將不再被剪裁到視圖的可見邊界。我正在尋找一個乾淨的方法來解決這個問題。

1

Guillaume對於clipsToBounds設置是正確的。

這有點亂,但你總是可以在UITextView背後添加一個清晰的視圖,並在它上面放一個陰影......