2015-10-06 36 views
0

我在iOS中有一個圖像。圖像不是太大。現在,當我將該圖像顯示爲配置文件圖片時,我現在也希望將該配置文件圖像顯示爲當前屏幕背景,具有半透明效果。這是半透明的在iPhone & iPad [![在這裏輸入圖片] [1]] [1]。 我曾嘗試下面的代碼如何在iOS中使圖像半透明?

imageView.alpha=0.3f; 

但是這不會使圖像半透明。

請告訴我該怎麼做?

+0

你有這種設計的任何示例代碼?我沒有得到這個問題 – engmahsa

+0

看到我有我的形象作爲配置文件圖像現在我想把我的個人資料圖像作爲背景與半透明效果,所以我模糊的梯度圖像將作爲背景可見@ engmahsa – TechGuy

回答

4

爲了使圖像變爲半透明,你可以使用視覺效果,這樣

UIVisualEffect *blurEffect; 
blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]; 

UIVisualEffectView *visualEffectView; 
visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect]; 

visualEffectView.frame = self.YOURIMAGEVIEW.bounds; 
[self.YOURIMAGEVIEW addSubview:visualEffectView]; 
0
imageView.backgroundColor = [UIColor clearColor]; 
imageView.opaque = NO; 
imageView.alpha=0.3f; 
0

你在找什麼是UIVibrancyEffectUIVisualEffectView

什麼Alpha做的是,它可以讓你透過度水平爲0低到1高。

可以實現通過本所要求的效果:

// Create the vibrancy effect - to be added to the blur 
let vibrancyEffect = UIVibrancyEffect(forBlurEffect: blurEffect) 
let vibrancyEffectView = UIVisualEffectView(effect: vibrancyEffect) 

//Add your contentview as subview 
vibrancyEffectView.contentView.addSubview(contentView) 
blurEffectView.contentView.addSubview(vibrancyEffectView) 

//Then add the blurEffectView to your view hierarchy to display it: 
containerView.addSubview(blurEffectView) 

結帳的詳細信息:UIVisualEffects