IntroScreen
由 Swift 编写的用于 iOS 的美丽开场屏幕。
使用方法
- 创建如下的
IntroDataSource
struct MyIntroDataSource: IntroDataSource {
let numberOfPages = 3
// Set to true, if you want to fade out the last page color into black.
let fadeOutLastPage: Bool = false
func viewController(at index: Int) -> IntroPageViewController? {
switch index {
case 0:
return DefaultIntroPageViewController(
index: index,
hue: 30/360,
title: "First page",
subtitle: "This is the first page.",
image: UIImage(named: "first")!
)
case 1:
return DefaultIntroPageViewController(
index: index,
hue: 60/360,
title: "Second page",
subtitle: "This is the second page.",
image: UIImage(named: "second")!
)
case 2:
return DefaultIntroPageViewController(
index: index,
hue: 90/360,
title: "Third page",
subtitle: "This is the third page.",
image: UIImage(named: "third")!
)
default:
return nil
}
}
}
- 使用数据源创建
IntroViewController
let viewController = IntroViewController(dataSource: dataSource)
就是这样!
自定义
当然,您也可以为页面使用自定义视图控制器。只需扩展 IntroPageViewController
或使用实现 IntroPage
的 UIViewController
。请注意,您必须提供清晰的背景,以便颜色可见。
颜色使用 HSV 颜色模型。因此,您只需在 Intro 页面上提供色调即可
public protocol IntroPage: AnyObject {
// ...
/// The color hue between 0 & 1 for the HSV color.
var hue: CGFloat { get }
}
您可以在 IntroViewController 中同时更改所有页面的饱和度和亮度
let viewController = IntroViewController(
dataSource: dataSource,
saturation: 0.85,
brightness: 0.9
)
如果您想以编程方式导航页面(例如,如果您想添加按钮),可以使用以下方法
introViewController.nextPage() // navigate forward
introViewController.previousPage() // navigate backwards
示例
要运行示例项目,请克隆仓库,然后首先从示例目录中运行 pod install
安装
IntroScreen可以通过CocoaPods获取。要安装它,只需将以下行添加到您的Podfile中
pod 'IntroScreen'
作者
P1xelfehler, [email protected]
许可证
IntroScreen在MIT许可证下提供。有关更多信息,请参阅LICENSE文件。