2017-06-22 100 views
1

似乎無法找到這個答案...黑色陰影添加到UIView的maskView

所以我加一個遮蔽一個UIView像這樣

//create mask image for uiview 
UIImageView *imv = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.sentencesContainer.frame.size.width, self.sentencesContainer.frame.size.height)]; 
imv.image = new; 
self.sentencesContainer.maskView = imv; 

然後嘗試添加面具的影子。

self.sentencesContainer.maskView.layer.masksToBounds = NO; 
self.sentencesContainer.maskView.layer.cornerRadius = 10; 
self.sentencesContainer.maskView.layer.shadowOffset = CGSizeMake(distanceX, distanceY); 
self.sentencesContainer.maskView.layer.shadowRadius = 2; 
self.sentencesContainer.maskView.layer.shadowOpacity = opacity; 
self.sentencesContainer.maskView.layer.shadowColor = [UIColor blackColor].CGColor; 

但是陰影不會變成黑色。它只是保持與視圖相同的顏色。我已經嘗試向視圖圖層添加陰影,但是不會在蒙版部分獲得陰影。任何建議如何讓它變黑?

+0

你想爲UIView或UIImageview設置陰影嗎? –

+0

我想將陰影設置爲UIView.maskView。 self.sentencesContainer是一個UIView。 –

回答

1

也添加以下行。

self.sentencesContainer.maskView.clipsToBounds = NO; self.sentencesContainer.maskView.layer.zposition = 9999;

這樣它會使你的陰影效果超過其他視圖。

+0

謝謝,但這並不能解決我錯誤顏色的問題... –