一个易于使用的库,专为 iOS 应用程序的新用户体验而设计。使用 Swift 编写。
使您的视图控制器符合 ShowsABOnboardingItem
将以下变量添加到您的视图控制器
var onboardingToShow: [ABOnboardingItem] = []
var onboardingIndex: Int = 0
var currentBlurViews: [UIView] = []
var onboardingSection: Int = 0
将以下方法添加到您的视图控制器。由于 Swift 中选择器的限制,您将必须添加两个动作转发,如下所示
func userSkippedOnboarding() {
//Save the status
}
func userCompletedOnboarding() {
//Save the status
}
func shouldShowOnboardingOnThisVC() -> Bool {
//Your logic for whether or not to show onboarding
}
//Action forwarders
func skipOnboardingForwarder() {
self.skipOnboarding()
}
func showNextOnboardingItemForwarder() {
self.showNextOnboardingItem()
}
设置您想要显示的引导项目。有三种不同的 AbOnboardingItem
初始化,一个接受普通的 String
,一个接受 NSAttributedString
init(message: String, placement: RelativePlacement, blurredBackground: Bool, nextItemAutomaticallyShows: Bool = true, leftButtonTitle: String? = nil, rightButtonTitle: String? = nil, image: UIImage? = nil, textAlign: NSTextAlignment = .Left)
init(attributedString: NSAttributedString, placement: RelativePlacement, blurredBackground: Bool, nextItemAutomaticallyShows: Bool = true, leftButtonTitle: String? = nil, rightButtonTitle: String? = nil, image: UIImage? = nil, textAlign: NSTextAlignment = .Left)
message
: String
或 'attributedString': NSAttributedString
- 引导视图的文本内容。
placement
: RelativePlacement
- 引导项目将在屏幕上的位置。这里是 RelativePlacement
枚举
public enum RelativePlacement {
case Above(UIView),
Below(UIView),
RelativeToTop(CGFloat), #No arrow
RelativeToBottom(CGFloat), #No arrow
PointingUpAt(CGRect),
PointingDownAt(CGRect)
}
blurredBackground
: Bool
- 是否应该模糊背景
nextItemAutomaticallyShows
: Bool
- 当用户点击下一按钮后,下一个引导项目是否应该自动显示
leftButtonTitle
: String
- 后退按钮的定制标题
rightButtonTitle
: String
- 下一按钮的定制标题
image
: UIImage
- 引导项目顶部显示的图像
textAlign
: NSTextAlignment
- 主要标签的文本对齐方式
一旦设置好引导项目,就只需在屏幕上显示它们!只需调用 self.startOnboarding()
即可开始引导。
您可以通过 ABOnboardingSettings
结构定制颜色、字体、时间和引导项目显示的位置。
//Background and text
public static var OnboardingBackground = UIColor.whiteColor()
public static var OnboardingNextButtonBackground = UIColor.whiteColor()
public static var OnboardingText = UIColor.grayColor()
public static var OnboardingLaterText = UIColor.grayColor()
public static var BackgroundWhileOnboarding = UIColor.blackColor().colorWithAlphaComponent(0.85)
public static var Font = UIFont.systemFontOfSize(16)
//Rounded button
public static var ButtonBackgroundNormal = UIColor.redColor()
public static var ButtonBackgroundHighlighted = UIColor.clearColor()
public static var ButtonTextNormal = UIColor.whiteColor()
public static var ButtonTextHighlighted = UIColor.grayColor()
public static var ButtonBorderNormal = UIColor.clearColor()
public static var ButtonBorderHighlighted = UIColor.grayColor()
public static var ViewToShowOnboarding: UIView?
public static var AnimationDuration: NSTimeInterval = 0.5
public static var TouchesDisabledOnUncoveredRect: Bool = true
如果您正在使用 Cocoapods,请将以下行添加到您的 Podfile 中
pod 'ABOnboarding'
并在任何您想要显示引导的类中添加此导入语句
import ABOnboarding
在本存储库中有一个简短的示例应用。