OMAKOView 2.2.1

OMAKOView 2.2.1

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布最后发布2017年6月
SwiftSwift版本3.0
SPM支持SPM

Kevin LeongKevin Leong维护。




OMAKOView 2.2.1

  • Kevin Leong

OMAKOView

Readme Score

描述 规范
语言 Swift 3

概览

该库包含的自定义视图

名称 描述
弹出视图 & 加载指示器 一个弹出窗口,除了显示加载指示器外,还会显示标题和/或说明。
星型视图 使用UIBezierPath对象高度可配置的UIView星形。
部分可见的可滑动视图 一个部分可见的视图,它可以响应纵向滑动来显示和隐藏其内容。

目录

弹出视图

可定制的弹出视图,在指定时间间隔后可以淡出,并在关闭或完成时调用一个闭包。

Pop up view demo

配置

属性名称 描述 类型 默认
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

Star view demo

配置

在Interface Builder中,以下属性可用

Star view inspectable properties

属性名称 描述 类型 默认
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

用法

Star view variations

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

部分可见的可滑动视图

Partially Visible Swipeable View demo

用法

关于约束的重要说明

如果使用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()
    }
}

IBInspectable属性

Partially Visible Swipeable IBInspectable properties

名称 类型 描述
可见量 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 文件。