2016-10-22 21 views

回答

1

您可以使用一個漸變的圖像或CAGradientLayer用於此目的

CAGradientLayer添加到現有的按鈕:

CAGradientLayer *gradient = [CAGradientLayer layer]; 
gradient.frame = button.bounds; 
gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor whiteColor] CGColor], (id)[[UIColor blackColor] CGColor], nil]; 
[button.layer insertSublayer:gradient atIndex:0]; 
0

您可以使用圖像來顯示陰影。使用模糊圖像或更改imageview的alpha。

或者,如果你想以編程方式做到這一點,試試吧:

的OBJ C:

//create elliptical shadow for button through UIBezierPath 
CGRect ovalRect = button.bounds; 
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:ovalRect]; 

//applying shadow to path 
button.layer.shadowColor = [UIColor yourcolor].CGColor; 
button.layer.shadowOffset = CGSizeMake(0.0, 0.0); 
button.layer.shadowOpacity = 1.0; 
button.layer.shadowRadius = 3.0; 
button.layer.shadowPath = path.CGPath; 

斯威夫特:

//create elliptical shdow forimage through UIBezierPath 
var ovalRect = button.bounds 
var path = UIBezierPath(ovalInRect: ovalRect) 

//applying shadow to path 
button.layer.shadowColor = UIColor(white: 0.0, alpha: 0.5).CGColor 
button.layer.shadowOffset = CGSizeMake(0.0, 0.0) 
button.layer.shadowOpacity = 1.0 
button.layer.shadowRadius = 3.0 
button.layer.shadowPath = path.CGPath 

http://www.innofied.com/implementing-shadow-ios/兩者也看看了解更多:UIView with rounded corners and drop shadow?

我的另一個答案與此相關:Drop shadow in ios

+0

什麼是kShadowColor聽到? – Muju

+0

您想要應用的顏色。請檢查更新後的答案。 –

+0

通過使用您的代碼沒有發生。 – Muju