ShadowView是一个使UIView的阴影实现变得简单快捷的iOS阴影库。
🎉 🎊 .
为任何 UIView 添加简单阴影,以添加高斯模糊投影(作为阴影)。
目录
功能
- 从 storyboard 和 程序化 中轻松添加阴影。
- 添加视图的高斯模糊投影(如iOS 10音乐应用)。
- 从Storyboard自定义任何视图的边框宽度和边框颜色。
需求
- iOS 9.0+
- Xcode 8
安装
CocoaPods
您可以使用 CocoaPods 通过将其添加到您的 Podfile
中来安装 ShadowView
。
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
use_frameworks!
target '<Your Target Name>' do
pod 'ShadowView'
end
Carthage
- 通过 Homebrew 安装 Carthage
$ brew update
$ brew install carthage
-
将
github "PierrePerrin/ShadowView"
添加到您的 Cartfile。 -
运行
carthage update
。 -
从
Carthage/Build/iOS/
目录将ShadowView.framework
拖到您的 Xcode 项目 “通用” 设置中“链接的框架和库”部分。 -
将
$(SRCROOT)/Carthage/Build/iOS/ShadowView.framework
添加到 Carthage 的运行脚本阶段的《输入文件》中。
手动安装
- 下载并将所有文件拖放到您的项目中ShadowView目录下。
- 干得好!最棒的资金库现在已安装!
🎉 🎊 🎈
导入
为了获得最大好处,在导入 UIKit 的地方也导入 ShadowView
。
import UIKit
import ShadowView
工作原理
普通阴影
此阴影框架通过将其添加到视图层级来使用默认的 CoreGraphics 阴影。
layer.shadowColor : CGColor
layer.shadowRadius : CGFloat
layer.shadowOffset : CGSize
layer.shadowOpacity : Float
layer.shadowPath : CGPath?
投影高斯阴影
这里的实现方式不同。需要添加一个阴影容器,并且所有需要模糊阴影的视图都应该是此容器的子视图。 该容器获取所有子视图的屏幕,然后对其进行模糊处理。
使用示例
使用 Storyboard
普通阴影
任何视图在 storyboar 中都有新的参数,您可以通过这些参数来为视图添加自定义阴影。
投影高斯阴影
将一个UIView添加到您的ViewController中,将其类更改为ShadowView,然后将所有需要模糊阴影的视图插入其中。
编程实现
常规阴影
将阴影参数设置到您的视图中,阴影就会显示出来!
view.shadowRadius = 5
view.shadowOffset = CGSize.zero
view.shadowColor = UIColor.black.cgColor
view.shadowOpacity = 0.3
投影高斯阴影
创建您的容器ShadowView,然后添加需要阴影的视图。
let exampleShadowContainerView = ShadowView()
let imageView = UIImageView(image: #imageLiteral(resourceName: "sample.jpg"))
override func loadView() {
super.loadView()
exampleShadowContainerView.frame = self.view.bounds
exampleShadowContainerView.autoresizingMask = [.flexibleWidth,.flexibleHeight]
exampleShadowContainerView.shadowOffset = CGSize(width: 0, height: 10)
exampleShadowContainerView.shadowRadius = 20
self.view.addSubview(exampleShadowContainerView)
self.exampleShadowContainerView.addSubview(imageView)
imageView.center = exampleShadowContainerView.center
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
imageView.frame.size = CGSize(width: 200, height: 200)
imageView.center = exampleShadowContainerView.center
self.exampleShadowContainerView.updateShadow()
}
请参阅示例以获取更多信息。
参数
//Shared Paramerters
@IBInspectable public var shadowRadius : CGFloat
@IBInspectable public var shadowOffset : CGSize
@IBInspectable public var shadowColor : UIColor?
@IBInspectable public var shadowOpacity : Float
//Normal Shadow
@IBInspectable var shadowPath : CGPath?
//ShadowView only
///It changes the size of the projected shadow view.
@IBInspectable var shadowScale : CGFloat
///Changes the tint color of the blurred image
@IBInspectable var shadowTintColor : UIColor
///Changes the saturation of the blurred image (default:1)
@IBInspectable var shadowSaturation : CGFloat
注意
不要使用如滑块或ActivityIndicators等视图,阴影不会实时更新。建议使用静态视图,如标签、图片等。
贡献
我们非常欢迎对<强>ShadowView强>的贡献,有关更多信息,请查看<代码>LICENSE代码>文件。如果您发现任何问题,请打开一个工单。
元数据
皮埃尔·佩兰 – [email protected]
根据MIT许可证分发。更多信息请参阅LICENSE
。