PSPageControl 0.3.2

PSPageControl 0.3.2

测试已测试
语言语言 SwiftSwift
许可 MIT
发布最后发布2020年5月
SwiftSwift 版本4.0
SPM支持 SPM

Piotr Sochalewski维护。



  • Piotr Sochalewski

PSPageControl

Version License Platform

用法

要运行示例项目,请克隆仓库,然后首先在 Example 目录中运行 pod install命令。

要求

  • iOS 8.0+,tvOS 9.0+
  • Swift ** 4.0 ** 3.x (swift3 分支)

安装

PSPageControl 可以通过 CocoaPods 获得。要安装它,只需将以下行添加到 Podfile 即可

pod "PSPageControl"

演示

PSPageControl example
此处为GFY

使用

首先将库导入到你的视图控制器中。

import PSPageControl

然后在Storyboard/xib(或以编程方式创建)中添加一个UIView,将其类改为PSPageControl,并拖放到创建IBOutlet的位置。接下来,在viewDidLoad或其他需要使用的地方添加适当的代码。

override func viewDidLoad() {
    super.viewDidLoad()

    pageControlView.backgroundPicture = UIImage(named: "Background")
    pageControlView.offsetPerPageInPixels = 50

    // Prepare views to add
    var views = [UIView]()
    for index in 1...5 {
        let view = UIView(frame: self.view.frame)

        let label = UILabel(frame: CGRect(x: self.view.frame.width / 2.0 - 60.0, y: 40.0, width: 120.0, height: 30.0))
        label.textColor = .white
        label.font = UIFont(name: "HelveticaNeue-Bold", size: 24.0)
        label.textAlignment = .center
        label.text = "View #\(index)"

        view.addSubview(label)

        views.append(view)
    }

    pageControlView.views = views
}

更复杂的功能见此处。

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    let loremIpsum = ["Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin nibh augue, suscipit a, scelerisque sed, lacinia in, mi. Cras vel lorem. Etiam pellentesque aliquet tellus. Phasellus pharetra nulla ac diam. Quisque semper justo at risus.",
        "Donec venenatis, turpis vel hendrerit interdum, dui ligula ultricies purus, sed posuere libero dui id orci.",
        "Nam congue, pede vitae dapibus aliquet, elit magna vulputate arcu, vel tempus metus leo non est. Etiam sit amet lectus quis est congue mollis. Phasellus congue lacus eget neque.",
        "Phasellus ornare, ante vitae consectetuer consequat, purus sapien ultricies dolor, et mollis pede metus eget nisi. Praesent sodales velit quis augue.",
        "Cras suscipit, urna at aliquam rhoncus, urna quam viverra nisi, in interdum massa nibh nec erat."]

    pageControl.backgroundPicture = UIImage(named: "Background")
    pageControl.offsetPerPage = 40

    // Prepare views to add
    var views = [UIView]()

    for index in 1...5 {
        let view = UIView(frame: self.view.frame)

        let label = UILabel(frame: CGRect(x: self.view.frame.width / 2.0 - 60.0, y: 40.0, width: 120.0, height: 30.0))
        label.textColor = .white
        label.font = UIFont(name: "HelveticaNeue-Bold", size: 24.0)
        label.textAlignment = .center
        label.text = "View #\(index)"

        let description = UILabel(frame: CGRect(x: 30.0, y: 80.0, width: self.view.frame.width - 60.0, height: self.view.frame.height - 100.0))
        description.lineBreakMode = .byWordWrapping
        description.numberOfLines = 0
        description.textColor = .white
        description.font = UIFont(name: "HelveticaNeue-Light", size: 20.0)
        description.textAlignment = .center
        description.text = loremIpsum[index - 1]

        view.addSubview(label)
        view.addSubview(description)

        views.append(view)
    }

    pageControl.views = views
}

属性

PSPageControl有几个变量可以让你配置库。

  • backgroundPicture是在背景中显示的图片。请记住,它应该是水平截图,有合适的宽高比和高分辨率。
  • views是页面上要显示的UIView数组。
  • offsetPerPage是点击从一页翻到下一页时光标移动的偏移量。默认值为40
  • pageIndicatorTintColor是用于不活动页标指示器的UIColor
  • currentPageIndicatorTintColor是用于活动页标指示器的UIColor

作者

Piotr Sochalewski, sochalewski.github.io

许可

PSPageControl采用MIT许可。有关更多信息,请参阅LICENSE文件。