0
A
回答
4
更好的是您使用另一個圖像來顯示陰影。使用模糊圖像或更改imageview的alpha。
或者,如果你想以編程方式做到這一點,試試吧:
的OBJ C:
//create elliptical shadow for image through UIBezierPath
CGRect ovalRect = CGRectMake(0.0f, _imageView.frame.size.height + 10, _imageView.frame.size.width, 15);
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:ovalRect];
//applying shadow to path
_imageView.layer.shadowColor = kShadowColor.CGColor;
_imageView.layer.shadowOffset = CGSizeMake(0.0, 0.0);
_imageView.layer.shadowOpacity = 1.0;
_imageView.layer.shadowRadius = 3.0;
_imageView.layer.shadowPath = path.CGPath;
斯威夫特:
//create elliptical shdow forimage through UIBezierPath
var ovalRect = CGRectMake(0.0, imageView.frame.size.height + 10, imageView.frame.size.width, 15)
var path = UIBezierPath(ovalInRect: ovalRect)
//applying shadow to path
imageView.layer.shadowColor = UIColor(white: 0.0, alpha: 0.5).CGColor
imageView.layer.shadowOffset = CGSizeMake(0.0, 0.0)
imageView.layer.shadowOpacity = 1.0
imageView.layer.shadowRadius = 3.0
imageView.layer.shadowPath = path.CGPath
輸出:
從http://www.innofied.com/implementing-shadow-ios/兩者也看看了解更多:UIView with rounded corners and drop shadow?
+0
這適用於我。謝謝 – HPM
+0
歡迎。請接受並提出我的回答。 @HPM –
0
您可以使用CAShapeLayer這樣的:
的Objective-C:
// init CAShapeLayer
CAShapeLayer *shadowLayer = [CAShapeLayer layer];
shadowLayer.frame = CGRectMake(CGRectGetMinX(_imageView.frame), CGRectGetMaxY(_imageView.frame), _imageView.frame.size.width, _imageView.frame.size.height);
shadowLayer.path = [UIBezierPath bezierPathWithOvalInRect:shadowLayer.bounds].CGPath;
shadowLayer.fillColor = [UIColor colorWithWhite:0 alpha:0.02].CGColor;
shadowLayer.lineWidth = 0;
[self.view.layer addSublayer: shadowLayer];
斯威夫特3
let shadowLayer = CAShapeLayer()
shadowLayer.frame = CGRect(x: imageView.frame.minX, y: imageView.frame.maxY, width: imageView.frame.width, height: imageView.frame.height * 0.25)
shadowLayer.path = UIBezierPath(ovalIn: shadowLayer.bounds).cgPath
shadowLayer.fillColor = UIColor(white: 0, alpha: 0.02).cgColor
shadowLayer.lineWidth = 0
view.layer.addSublayer(shadowLayer)
輸出:
相關問題
- 1. 在knitr中投下陰影
- 2. 在Andengine中投下陰影
- 3. 在HyperLink上投下陰影效果
- 4. 在文字上投下陰影
- 5. 在HTML對象上投下陰影
- 6. 在無邊界WinForm上投下陰影
- 7. 在透明形狀上投下陰影?
- 8. 在Adobe Photoshop中投影陰影角度陰影
- 9. iOS SDK - 在蒙面圖像上投下陰影
- 10. QML文本投影陰影
- 11. 陰影貼圖在某些情況下無法正確投影陰影?
- 12. iOS:如何在UIView上添加投影和筆觸陰影?
- 13. ThreeJS不會投下任何陰影
- 14. C++ - 動態陰影投射
- 15. THREE.JS不會投射陰影
- 16. 在未裝飾的窗格中投下陰影! JAVAFX
- 17. 投影表上翻轉的陰影?
- 18. CSS3插入/內部投影陰影嗎?
- 19. iOS中的怪異陰影
- 20. ios 5 uiwebview陰影
- 21. iOS:下降陰影與銳利
- 22. 對文本塊中的文本投下陰影
- 23. 造型Div - 通過其他div的中間投下陰影
- 24. 在JButton上投下陰影/重複文本
- 25. 過濾器:只在背景上投下陰影
- 26. 是否可以在CSS盒子上投下陰影?
- 27. 如何使片段在其主機Activity上投下陰影?
- 28. 如何在iOS UIButton中添加陰影?
- 29. 在iOS中刪除鍵盤的陰影
- 30. GLGE:放下陰影
爲什麼不使用帶有幾乎透明的黑色橢圓另一圖像? – alexburtnik
您的對象?你是如何面向對象的。你試過什麼了? –
@Leo Natan紅色矩形是我的對象。其實它的imageview,我想投下imageview的陰影,如圖 – HPM