1
A
回答
2
CAGradientLayer將服務器你的目的 - 參考:
http://blog.apoorvmote.com/gradient-background-uiview-ios-swift/
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
相關問題
- 1. UICollectionViewCell陰影顏色
- 2. 如何讓OpenGL支持顏色陰影?
- 3. 如何計算顏色陰影代碼?
- 4. 如何控制SVG陰影的顏色?
- 5. 自定義陰影顏色
- 6. SVG:陰影的顏色
- 7. CSS文字陰影顏色
- 8. NSFontPanel:陰影顏色 - 你在哪裏?
- 9. 如何在matplotlib中分離陰影和邊緣顏色?
- 10. 如何在TeeChart中設置標題的陰影顏色?
- 11. 如何在Gtk2中設置陰影的顏色::框架
- 12. 顏色函數返回陰影較淺和陰影較暗
- 13. UIButton的陰影顏色和陰影偏移不顯示
- 14. 如何刪除下面的灰色陰影顏色FloatingActionButton
- 15. 如何將陰影背景白色更改爲其他顏色
- 16. 如何更改PHP中圖像的顏色,保持陰影
- 17. 如何在關注時將陰影顏色應用於Android EditText?
- 18. css3文字陰影文字顏色#037ECC
- 19. 更改ListView陰影顏色和大小
- 20. Android TV:VerticalGridFragment陰影尺寸和顏色
- 21. 默認的箱子陰影顏色?
- 22. 顏色陰影響應div的數量
- 23. 用3種隨機盒陰影顏色
- 24. 更改陰影的顏色上UIBezierPath
- 25. 無法更改CSS ::陰影顏色後
- 26. 更改Android上ImageView的陰影顏色
- 27. 更改UIBoolButtonItem的UIToolbar陰影顏色
- 28. jQuery。動畫背景顏色,框陰影和字體顏色
- 29. 將其顏色陰影設置爲其基本顏色c#
- 30. 當背景顏色清晰時,陰影不顯示顏色
您可以爲此使用漸變圖像或CAGradientLayer – alexburtnik