LPActionSheet是一款輕量級的仿微信彈出框
安裝
從CocoaPods安裝
CocoaPods可以優(yōu)雅地管理第三方庫(具體使用方式我在另一篇文章有詳細介紹,這里不再贅述)
- 第一步: 在Podfile文件中寫入如下代碼
pod 'LPActionSheet', '~> 1.0'
- 第二步: 將文件安裝進項目中
pod install
從Github上手動添加
- 第一步: 到 這里 下載代碼文件,將LPActionSheet/LPActionSheet文件夾拖到項目中
- 第二步: 將頭文件加入項目中 #import "LPActionSheet.h"
如何使用LPActionSheet
你可以像這樣實例化一個對象 (該方法為指定初始化器,其他初始化方法都會調(diào)用該方法,NS_DESIGNATED_INITIALIZER)
- (instancetype)initWithTitle:(NSString *)title
cancelButtonTitle:(NSString *)cancelButtonTitle
destructiveButtonTitle:(NSString *)destructiveButtonTitle
otherButtonTitles:(NSArray *)otherButtonTitles
handler:(LPActionSheetBlock)actionSheetBlock NS_DESIGNATED_INITIALIZER;
你可以像這樣快速返回一個實例化對象
+ (instancetype)actionSheetWithTitle:(NSString *)title
cancelButtonTitle:(NSString *)cancelButtonTitle
destructiveButtonTitle:(NSString *)destructiveButtonTitle
otherButtonTitles:(NSArray *)otherButtonTitles
handler:(LPActionSheetBlock)actionSheetBlock;
使用如下方法彈出該視圖
- (void)show;
終極解決方案 (推薦)
+ (void)showActionSheetWithTitle:(NSString *)title
cancelButtonTitle:(NSString *)cancelButtonTitle
destructiveButtonTitle:(NSString *)destructiveButtonTitle
otherButtonTitles:(NSArray *)otherButtonTitles
handler:(LPActionSheetBlock)actionSheetBlock;
Demo
[LPActionSheet showActionSheetWithTitle:@"This is a title, you can show some prompt here"
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:@"Destructive"
otherButtonTitles:@[@"First choice", @"Second choice", @"Third choice"]
handler:^(LPActionSheet *actionSheet, NSInteger index) {
NSLog(@"%ld", index);
}];
豎屏

LPActionSheet.png
橫屏

LPActionSheet_Landscape.png
后續(xù)更新
該框架后續(xù)會在Github上維護更新,歡迎關(guān)注