描述 | 规范 |
---|---|
语言 | Swift 3 |
该库包含的自定义视图
名称 | 描述 |
---|---|
弹出视图 & 加载指示器 | 一个弹出窗口,除了显示加载指示器外,还会显示标题和/或说明。 |
星型视图 | 使用UIBezierPath 对象高度可配置的UIView 星形。 |
部分可见的可滑动视图 | 一个部分可见的视图,它可以响应纵向滑动来显示和隐藏其内容。 |
可定制的弹出视图,在指定时间间隔后可以淡出,并在关闭或完成时调用一个闭包。
属性名称 | 描述 | 类型 | 默认 |
---|---|---|---|
titleText | 可定制的标题文本 | NSMutableAttributedString | N/A |
bodyText | 可定制的正文文本 | NSMutableAttributedString | N/A |
titleFontName | 标题字体名称。传递给UIFont(name:size:) | String | nil 。将默认为系统字体。 |
bodyFontName | 正文字体名称。传递给UIFont(name:size:) | String | nil 。将默认为系统字体。 |
titleFontColor | 标题字体颜色 | UIColor | 深蓝色 |
bodyFontColor | 正文字体颜色 | UIColor | 紫色 |
spinnerBorderColor | 加载指示器边框颜色 | UIColor | 浅白色 |
spinnerFillColor | 用于保持相同颜色的加载指示器。 | UIColor | 浅蓝色 |
spinnerBorderWidth | 加载指示器边框宽度。 | CGFloat | 5.0 |
padding | 元素之间的填充。例如,加载指示器、标题、正文。 | CGFloat | 10.0 |
cornerRadius | 如果设置,将剪切视图并将边缘圆角到指定的值。 | CGFloat | 10.0 |
spinnerSizeInPoints | 加载指示器视图的大小。 | CGFloat | 20.0 |
spinnerDuration | 旋转和任何其他加载指示器动画的持续时间。 | CGFloast | 2.0 |
以标题和正文显示标准弹出窗口。
popUpView = OMAKOPopUpView()
popUpView.titleText = NSMutableAttributedString(string: "Title")
popUpView.bodyText = NSMutableAttributedString(string: "Body")
// Pass in the view that the popup should be centered in.
// The pop up will add itself to the view's hierarchy.
popUpView.display(parentView: view)
隐藏弹出窗口
popUpView.hide(completion: nil)
// Or a completion block can be passed in:
popUpView.hide() { print("Do something after the popup is dismissed") }
显示持续一定时间的弹出窗口
/*
Will dismiss the popup after 5 seconds.
A completion block can be passed in, which will execute after the popup
is dismissed.
*/
popUpView.display(parentView: view, withDuration: 5.0, completion: nil)
popUpView = OMAKOPopUpView()
popUpView.titleText = NSMutableAttributedString(string: "Loading")
popUpView.spinnerSizeInPoints = 40.0 // Results in a larger spinner.
popUpView.displaySpinner(parentView: view, spinnerType: .square) // Square spinner
popUpView.displaySpinner(parentView: view, spinnerType: .star) // Star spinner
// Hide
popUpView.hide(completion: nil)
一个使用UIBezierPath
对象绘制的可高度自定义的星形的UIView
。
在Interface Builder中,以下属性可用
属性名称 | 描述 | 类型 | 默认 |
---|---|---|---|
strokeWidth | 星星的边框宽度。 | CGFloat | 5.0 |
hasStroke | 如果为真,将渲染边框。 | 布尔值 | false |
strokeColor | 边框颜色。 | UIColor | 红色 |
fillColor | 星星的填充颜色。 | UIColor | 浅蓝色 |
innerToOuterRadiusRatio | 确定星星的粗细。接近1.0的值将使星星的臂变宽,而接近0.0的值将使星星的臂变细。 | CGFloat | 0.45 |
starToViewRatio | 星星大小与其视图的相对比分。范围:0.0到1.0。 | CGFloat | 1.0 |
cacheVertices | 将缓存顶点位置。如果期望顶点位置在draw(_:) 渲染调用之间发生变化,请将此设置为false。 | 布尔值 | true |
var starView = OMAKOStarView()
starView.hasStroke = true
starView.strokeWidth = 5.0
starView.strokeColor = UIColor.red
starView.fillColor = UIColor.yellow
starView.innerToOuterRadiusRatio = 0.25 // Results in a thinner star.
starView.starToViewRatio = 0.8 // Results in a smaller star.
由于视图是UIView
的子类,圆角切边将星星绘制在圆形内。
var starView = OMAKOStarView()
// Creates a circular border. The usual UIView properties are available.
starView.layer.cornerRadius = starView.bounds.width/Float(2)
starView.layer.borderWidth = 5.0
starView.layer.borderColor = UIColor.red.cgColor
starView.clipToBound = true
如果使用Interface Builder,必须设置视图的宽度约束。
在构建时删除
占位符复选框必须选中宽度约束。
Interface Builder会自动生成约束,如果不遵循上述步骤,这可能会导致约束冲突。
如果视图的高度是动态的,还需要为高度做同样的设置。例如,包含动态文本的多行标签。
UIViewController
示例class ViewController: UIViewController {
@IBOutlet weak var containerView: OMAKOPartiallyVisibleSwipeableView!
@IBOutlet weak var titleLabel: UILabel!
let titleLoremIpsum = "Qui officia deserunt anim id est laborum."
override func viewDidLoad() {
super.viewDidLoad()
// Make labels multiline and add text
titleLabel.numberOfLines = 0
titleLabel.text = titleLoremIpsum
/*
`setupView(bottomLayoutGuide:)` should be called after any
changes are made to subviews that may affect the size of the
`containerView`. E.g., Dynamically setting multiline label text.
Optionally, `setupView()` can be called without paramters and this
will by default pin the view to the bottom of the superview.
Pinning the view to the `bottomLayoutGuide`, however, is preferred.
*/
containerView.setupView(bottomLayoutGuide: bottomLayoutGuide)
}
override func didRotateFromInterfaceOrientation(fromInterfaceOrientation: UIInterfaceOrientation) {
// Must be called on device orientation changes.
// Screen rotations will change the height of the `container view`,
// and `onRotate()` accounts for any changes.
containerView.onRotate()
}
}
名称 | 类型 | 描述 | 值 |
---|---|---|---|
可见量 | CGFloat | 视图初始应可见的高度比例。 | 1.0 表示完全可见,0.0 表示完全隐藏。默认值为0.4 ,即视图高度的40%可见。 |
相对宽度 | CGFloat | 视图相对于其父视图的宽度。 | 1.0 与父视图宽度相同,而0.0 使视图宽度为0。默认值为0.75 或父视图宽度的四分之三。 |
居中对齐 | 布尔值 | 在父视图中居中视图。 | 默认设置为true 。 |
以下属性用于调整动画的振荡和弹跳。有关更多详细信息,请参阅苹果开发者文档中的animateWithDuration
与弹簧阻尼。
名称 | 类型 | 描述 | 值 |
---|---|---|---|
duration | CGFloat | 动画应该持续多长时间,以秒为单位。 | 如果<= 0 ,则不会应用动画。默认设置为1.5 秒。 |
damping ratio | CGFloat | 所需的弹跳量。 | 使用 1 以无振荡的方式平稳减速。接近 0 的值会增加振荡/反弹。值越高,振荡停止得越快。默认设置为 0.5 。 |
弹簧速度 | CGFloat | 弹簧的初始速度。阻尼比将按比例减小此值,直到速度达到0。 | 更高的值会增加振荡速度。默认设置为 0.5 。 |
要运行示例项目,请先克隆仓库,然后从示例目录运行 pod install
。
OMAKOView 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中
pod "OMAKOView"
Kevin Leong, [邮箱地址可见]
OMAKOView 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。