TBActionSheet 是一个小型库,可让您用可在 iOS 应用程序中使用的漂亮且完全可自定义的操作表来替换 Apple 不可自定义的UIActionSheet
。默认样式为iOS9/10,您可以制作自己的样式。享受!
以下是一些展示 TBActionSheet 强大个性化的图片。您可以动态更改 UI:
顺便说一句, TBActionSheet
还支持自定义动画!
要运行示例项目,请克隆存储库并运行 MTDemo 目标。
CocoaPods 是 Cocoa 项目的依赖管理器。您可以使用以下命令安装它:
$ gem install cocoapods
要使用 CocoaPods 将 TBActionSheet 集成到 Xcode 项目中,请在Podfile
中指定它:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
use_frameworks!
target 'MyApp' do
pod 'TBActionSheet'
end
您需要将“MyApp”替换为您的项目名称。
然后,运行以下命令:
$ pod install
Carthage 是一个去中心化的依赖管理器,它可以构建您的依赖项并为您提供二进制框架。
您可以使用以下命令通过 Homebrew 安装 Carthage:
$ brew update
$ brew install carthage
要使用 Carthage 将 TBActionSheet 集成到 Xcode 项目中,请在Cartfile
中指定它:
github "yulingtianxia/TBActionSheet"
运行carthage update
来构建框架并将构建的TBActionSheetKit.framework
拖到您的 Xcode 项目中。
只需将“源”文档文件夹拖到您的项目中即可。
您可以参考TBAlertControllerDemo项目中的“ViewController.m”。基本用法与“UIActionSheet”相同。
为了让TBActionSheet看起来像微信风格,你可以设置TBActionShet
或其UIAppearance
的这些属性,如下所示:
sheetWidth = MIN(kScreenWidth, kScreenHeight);
backgroundTransparentEnabled = NO;
rectCornerRadius = 0;
基本用法与UIActionSheet
相同。您只需将UIActionSheet
替换为TBActionSheet
即可。如果您想自定义操作表,只需配置一些属性即可。
GitHub wiki 可以帮助您掌握高级用法。
还有一个TBActionSheet
的示例项目。
此存储库还包括TBAlertController
,它统一了UIAlertController
、 UIAlertView
和UIActionSheet
。 TBAlertController
将在 iOS 8.2 及更高版本上使用UIAlertController
。相反,它将使用UIAlertView
或UIActionSheet
。
TBAlertController
的 API 用法与UIAlertController
类似。我还提供TBAlertAction
而不是UIAlertAction
。
有一个例子:
TBAlertController *controller = [TBAlertController alertControllerWithTitle:@"TBAlertController" message:@"AlertStyle" preferredStyle:TBAlertControllerStyleAlert];
TBAlertAction *clickme = [TBAlertAction actionWithTitle:@"点我" style: TBAlertActionStyleDefault handler:^(TBAlertAction * _Nonnull action) {
NSLog(@"%@",action.title);
}];
TBAlertAction *cancel = [TBAlertAction actionWithTitle:@"取消" style: TBAlertActionStyleCancel handler:^(TBAlertAction * _Nonnull action) {
NSLog(@"%@",action.title);
}];
[controller addAction:clickme];
[controller addAction:cancel];
[self presentViewController:controller animated:YES completion:nil];
有关TBAlertController
的更多信息,请访问我的博客的这篇文章。
yulingtianxia, [email protected]
TBActionSheet 在 MIT 许可下可用。有关详细信息,请参阅许可证文件。