RFAboutView-Swift
RFAboutView 是一个简单易用的解决方案,可以在应用中显示版权、支持、隐私等信息,同时自动致谢第三方 CocoaPods 的开发者。RFAboutView 使用 AutoLayout,可以用于 iPhone 和 iPad 应用。
其主要特性包括
- 显示应用名称和版权信息。
- 显示可选的网址链接,在 Safari 视图控制器中打开。
- 显示可选的电子邮件地址链接。
- 如果用户点击电子邮件链接,将打开
MFMailComposeViewController
,(可选)预填用于支持的诊断信息:应用名称和版本、当前设备、当前 iOS 版本、首选设备语言。 - 显示您指定的带有其他信息的附加按钮(例如您的服务条款或隐私策略)。
- 显示项目所用所有 CocoaPods 的致谢信息。使用 CocoaPods 自动创建的致谢文件,几乎不需要您做任何工作。更多信息请见下文的“自动致谢”。
- 设计简洁现代,提供众多自定义选项。
屏幕截图
用法
要使用 RFAboutView,首先导入它
import RFAboutView_Swift
然后,初始化一个 RFAboutViewController 并将其添加到 UINavigationController。RFAboutViewController 必须始终用于导航堆栈中。以下是一个完整的示例
// First create a UINavigationController (or use your existing one).
// The RFAboutView needs to be wrapped in a UINavigationController.
let aboutNav = UINavigationController()
// Initialise the RFAboutView:
let aboutView = RFAboutViewController(copyrightHolderName: "ExampleApp, Inc.", contactEmail: "[email protected]", contactEmailTitle: "Contact us", websiteURL: NSURL(string: "http://example.com"), websiteURLTitle: "Our Website")
// Set some additional options:
aboutView.headerBackgroundColor = .blackColor()
aboutView.headerTextColor = .whiteColor()
aboutView.blurStyle = .Dark
aboutView.headerBackgroundImage = UIImage(named: "about_header_bg.jpg")
// Add an additional button:
aboutView.addAdditionalButton("Privacy Policy", content: "Here's the privacy policy")
// Add an acknowledgement:
aboutView.addAcknowledgement("An awesome library", content: "License information for the awesome library")
// Add the aboutView to the NavigationController:
aboutNav.setViewControllers([aboutView], animated: false)
// Present the navigation controller:
self.presentViewController(aboutNav, animated: true, completion: nil)
通过Swift Package Manager安装
请在您的 Package.swift
文件中添加以下内容(或通过Xcode的GUI添加)
.package(url: "https://github.com/fouquet/RFAboutView-Swift", from: "3.0.0")
通过CocoaPods安装
RFAboutView可通过CocoaPods获取。要安装,请简单地将其以下行添加到您的Podfile文件中
pod "RFAboutView-Swift", '~> 3.0.0'
use_frameworks!
通过Carthage安装
要使用Carthage安装RFAboutView,请将以下行添加到您的 Cartfile
github "fouquet/RFAboutView-Swift"
通过CocoaPods自动添加许可信息
每次您运行 pod update
或 pod install
,CocoaPods都会自动生成一个文件,包含项目中所有CocoaPods使用的版权和许可证信息。RFAboutView使用此文件来显示许可信息。要使用它,请将位于 <Project Root>/Pods/Target Support Files/Pods-<Target Name>
目录中的文件 Pods-<Target Name>-acknowledgements.plist
复制到您的项目中,并将其命名为 Acknowledgements.plist
。如果您想使用其他名称,可以将 RFAboutViewController
的 acknowledgementsFilename
属性设置为新的名称(无plist扩展名)。
要自动化此过程,可以将以下代码段添加到您的 Podfile
post_install do |installer|
require 'fileutils'
FileUtils.cp_r('Pods/Target Support Files/Pods-<Target Name>/Pods-<Target Name>-acknowledgements.plist', '<Project Dir>/Acknowledgements.plist', :remove_destination => true)
end
请注意,目录名称可能因项目设置和是否使用不同的目标而有所不同。请检查您的本地项目目录,并相应地更改代码段。此外,不要忘记将 Acknowledgements.plist
文件添加到您的Xcode项目中。
本地化和修改默认文本
如果您想为您的应用程序本地化RFAboutView,或者想要更改默认文本,您可以使用示例应用程序中的 RFAboutView.strings 文件作为模板。
自定义选项
RFAboutView包含许多自定义选项。有关完整文档,请参阅文件 RFAboutView.swift
。
示例项目
要运行示例项目,请克隆仓库,然后从示例目录运行 pod install
。
需求
RFAboutView需要iOS 12.0和Xcode 12(用于Swift 5.3)。
作者
René Fouquet,[email protected] 在Twitter上关注我 @renefouquet
许可证
RFAboutView可在MIT许可证下使用。有关更多信息,请参阅LICENSE文件。