构建免费应用最重要的部分之一是将忠实的用户转化为付费客户。大多数成功的应用都投入时间来对用户进行出色的销售,全部在一个视图中。
UpsellViewController 是一个库,允许您创建可定制的警报视图控制器,向您的应用用户推销产品。这个库在某种程度上受到 PMAlertController 的启发。
功能
-
自定义标题和副标题
-
自定义分页滚动视图,具有无限页面
-
具有自动滚动功能
-
自适应操作按钮
-
Cocoapods
要求
-
iOS 11.0+
-
Xcode 10+
-
了解如何通过 XIB 文件创建视图
CocoaPods
CocoaPods 是 Cocoa 项目的依赖项管理器。您可以使用以下命令安装它:
$ gem install cocoapods
要通过 CocoaPods 将 UpsellViewController
集成到您的 Xcode 项目中,在您的 Podfile
中指定它:
target 'MyApp' do
pod 'UpsellViewController', '~> 1.0.3'
end
然后,运行以下命令:
$ pod install
使用方法
UpsellViewController极易于使用,但需要了解如何使用XIB文件创建自定义UIView
。作为一名开发者,你的工作是将自定义UIView
作为一个XIB来创建。这个自定义UIView
会显示你希望用户可以滚动浏览的内容。理想情况下,这个视图将显示应用中包含的所有高级订阅功能。
在UpsellViewController
中,根据你要分页的内容数量,合理地间隔自定义UIView
的内容非常重要。例如,如果你使用带有五个页面的UpsellViewController
进行初始化,你将希望你的自定义UIView
的每个焦点区域只占用自定义视图的20%。同样,一个三个页面的UpsellViewController
应该确保自定义UIView
的每个焦点区域只占用自定义视图的33.33%,依此类推。
展示包含5页内容的UpsellViewController
//This code works with Swift 5
//Get all views in the custom view's xib file
let allViewsInXibArray = Bundle.main.loadNibNamed("PromoView1", owner: self, options: nil)
//Grab the view in the xib's array of items
let promoView = allViewsInXibArray!.first as! UIView
//Initialize your UpsellViewController
let upsellVC = UpsellViewController(title: "Refer a Friend and You'll Both Get Bandmate Plus, for Life!", subtitle: "With Plus, you can...", promoView: promoView, numberOfPages: 5)
//Create some actions for your user to interact with the UpsellViewController
let cancel = UpsellAction(title: "Cancel", style: .cancel)
upsellVC.addAction(learnMore)
let doSomeAction = UpsellAction(title: "Do Something", style: .default) {
print("Did something")
}
upsellVC.addAction(referAFriend)
//Present our UpsellViewController
present(upsellVC, animated: false, completion: nil)
自定义你的UpsellViewController
//Initialize your UpsellViewController
let upsellVC = UpsellViewController(title: "Some title", subtitle: "Some subtitle", promoView: promoView, numberOfPages: 3)
//Change the title/subtitle colors
upsellVC.titleLabel.textColor = UIColor.blue
upsellVC.subtitleLabel.textColor = UIColor.green
//Toggle autoscroll...
upsellVC.isAutoScrollEnabled = false
upsellVC.isAutoScrollEnabled = true
//...or change the speed at which your UpsellViewController autoscrolls
//upsellVC.autoScrollBuffer is the amount of time, in seconds, the UpsellViewController will wait between autoscrolling the content view. Lower = faster
upsellVC.autoScrollBuffer = 5
//upsellVC.autoScrollSpeed is the amount of time, in seconds, the UpsellViewController takes to animate the autoscrolling of the content view. Lower = faster
upsellVC.autoScrollSpeed = 0.3
//Change the page control tint colors
upsellVC.pageIndicatorTintColor = .blue
upsellVC.currentPageIndicatorTintColor = .green
//Then go ahead and add your actions for your user to interact with your UpsellViewController
自定义你的UpsellActions
//Crate your button
let oneMonth = UpsellAction(title: "1 MONTH", style: .default) {
print("Subscribing for one month")
}
//Hide the separator
oneMonth.showSeparator = false
//Set the button's corner radius, as a fraction of the button's height (0.5 will round your button's corners)
oneMonth.cornerRadius = 0.5
//Set the button's background color
oneMonth.backgroundColor = UIColor(red: 81/255, green: 189/255, blue: 209/255, alpha: 1)
//Change the button's title color
oneMonth.setTitleColor(.white, for: .normal)
//Add the action to your UpsellViewController
upsellVC.addAction(oneMonth)
贡献指南
-
如果你需要帮助或想提出一般性疑问,请提交一个问题。
-
如果你发现了一个错误,请提交一个问题。
-
如果你有功能建议,请提交一个问题。
-
如果你想做出贡献,请提交一个拉取请求。
致谢
由David Chopin制作.
查看我的
💼 LinkedIn
💻 StackOverflow
我将于2020年5月大学毕业,目前正在寻找工作! :)
MIT授權
UpsellViewController遵守MIT授權。詳情請參考LICENSE文件。