PBWebViewController
是 iOS 中的一个轻量级、简单且可定制的网页浏览器组件。它只有 2 个源文件,无图片,大约 300 行代码,并且是用现代 Cocoa 开发技术构建的。
只需将 PBWebViewController
文件夹拖放到您的项目中或将其添加到您的 Podfile
中。
PBWebViewController
在 iPhone 和 iPad 上工作,支持所有方向,并旨在与 UINavigationController
一起使用。您只需要设置其属性,然后将其推入即可。以下是一个简单的示例
// Initialize the web view controller and set it's URL
self.webViewController = [[PBWebViewController alloc] init];
self.webViewController.URL = [NSURL URLWithString:@"http://www.apple.com"];
// These are custom UIActivity subclasses that will show up in the UIActivityViewController
// when the action button is clicked
PBSafariActivity *activity = [[PBSafariActivity alloc] init];
self.webViewController.applicationActivities = @[activity];
// This property also corresponds to the same one on UIActivityViewController
// Both properties do not need to be set unless you want custom actions
self.webViewController.excludedActivityTypes = @[UIActivityTypeMail, UIActivityTypeMessage, UIActivityTypePostToWeibo];
// Push it
[self.navigationController pushViewController:self.webViewController animated:YES];
查看示例项目以了解更多高级用法。
PBWebViewController
可以安全地子类化以实现自定义行为。覆盖 load
和 UIWebViewDelegate
方法以进行挂钩,但不要忘记调用 super
以利用 PBWebViewController
提供的功能。
示例项目中使用了简单的子类。
PBWebViewController
将当前 URL 设置为唯一的操作项目,如果没有提供,则使用此设置。您可以通过这种方式完全自定义在单击操作按钮时显示的所有内容。
另一种实现相同结果的方法是,在子类中覆盖 activityItems
和 applicationActivities
请在 PBWebViewController.m
中的 action:
方法查看更多详细信息。
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)