2013-04-29 100 views
0

我搜索了很多,但我不能找到,如果你按下一個按鈕,你可以怎麼變黑了的UIImageView ...變暗的UIImage的

我和過濾器等嘗試過,但事實並非如此工作。

那麼我該如何做到這一點?

+0

什麼是「etc」在這種情況下? – 2013-04-29 12:19:27

+0

您嘗試過的任何代碼示例? – 2013-04-29 12:19:33

+0

我試過的例子是,但它都沒有工作 – user2332018 2013-04-29 12:21:32

回答

0

爲了使UIImage變暗,你應該嘗試GPUImage,這個框架有幾個過濾器,比如GPUImageBrightnessFilter,GPUImageContrastFilter和GPUImageSaturationFilter,它們可以幫助你做你需要的。

你還可以找到幾個關於如何使用這個框架here的例子。

-1

對於一個非常簡單的,但愚蠢的方法,我建議你創建一個帶有黑色背景顏色的新的UIView,其alpha設置爲0.5以下,設置其框架您UIImageView.frame並把它放在它上面:

UIView *tmpView = [[UIView alloc] initWithFrame:myImageView.frame.size.height]; 
tmpView.backgroundColor = [UIColor blackColor]; 
tmpView.alpha = 0.5 
//add it on button press 
[myImageView addSubview:tmpView]; 

雖然我不建議這樣做,它可能是更容易把握比那些GPUImage過濾器

0

您可以在imageView.Add下面的代碼添加CAGradientLayer到按鈕按下事件。

let gradientLayer = CAGradientLayer() 
gradientLayer.frame = self.imageView.bounds 
gradientLayer.colors = [UIColor.clearColor().CGColor,UIColor.blackColor().CGColor] 
self.imageView.layer.addSublayer(gradientLayer)