iOS-UIKit框架学习—UIActionSheet

使用UIActionSheet类可以把一套如何继续给定任务的替代品给用户。您还可以使用行动表,以提示用户确认是否有潜在危险的行动。该行动表包含一个可选的标题和一个或多个按钮,其中每个对应采取的行动。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
@protocol UIActionSheetDelegate;
// iOS 2.0 - iOS 8.3可用 使用UIAlertController顶替
NS_CLASS_DEPRECATED_IOS(2_0, 8_3, "UIActionSheet is deprecated. Use UIAlertController with a preferredStyle of UIAlertControllerStyleActionSheet instead") __TVOS_PROHIBITED
@interface UIActionSheet : UIView
// 初始化设置标题、代理、操作按钮
- (instancetype)initWithTitle:(nullable NSString *)title delegate:(nullable id<UIActionSheetDelegate>)delegate cancelButtonTitle:(nullable NSString *)cancelButtonTitle destructiveButtonTitle:(nullable NSString *)destructiveButtonTitle otherButtonTitles:(nullable NSString *)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION NS_EXTENSION_UNAVAILABLE_IOS("Use UIAlertController instead.");
// 代理
@property(nullable,nonatomic,weak) id<UIActionSheetDelegate> delegate;
// 标题属性
@property(nonatomic,copy) NSString *title;
// 操作栏的风格
@property(nonatomic) UIActionSheetStyle actionSheetStyle; // default is UIActionSheetStyleAutomatic.
// 在操作栏中添加自定义按钮
- (NSInteger)addButtonWithTitle:(nullable NSString *)title;
// 返回指定索引按钮的标题
- (nullable NSString *)buttonTitleAtIndex:(NSInteger)buttonIndex;
// 操作栏的按钮数
@property(nonatomic,readonly) NSInteger numberOfButtons;
// 取消按钮的下标
@property(nonatomic) NSInteger cancelButtonIndex;
// 破坏那妞的下标
@property(nonatomic) NSInteger destructiveButtonIndex;
// 第一个更多按钮的下标
@property(nonatomic,readonly) NSInteger firstOtherButtonIndex;
// 接收器是否显示
@property(nonatomic,readonly,getter=isVisible) BOOL visible;
// 显示一个来自指定工具栏的操作栏
- (void)showFromToolbar:(UIToolbar *)view;
// 显示一个来自指定标签栏的操作栏
- (void)showFromTabBar:(UITabBar *)view;
// 显示一个来自指定BarButtonItem的操作栏
- (void)showFromBarButtonItem:(UIBarButtonItem *)item animated:(BOOL)animated NS_AVAILABLE_IOS(3_2);
// 显示一个来自指定矩形的操作栏
- (void)showFromRect:(CGRect)rect inView:(UIView *)view animated:(BOOL)animated NS_AVAILABLE_IOS(3_2);
// 显示一个来自指定视图的操作栏
- (void)showInView:(UIView *)view;
// 隐藏弹出框
- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated;
@end
__TVOS_PROHIBITED
@protocol UIActionSheetDelegate <NSObject>
@optional
// 点击按钮操作调用
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex NS_DEPRECATED_IOS(2_0, 8_3) __TVOS_PROHIBITED;
// 点击取消操作按钮调用
- (void)actionSheetCancel:(UIActionSheet *)actionSheet NS_DEPRECATED_IOS(2_0, 8_3) __TVOS_PROHIBITED;
// 即将弹出操作栏之前调用
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet NS_DEPRECATED_IOS(2_0, 8_3)__TVOS_PROHIBITED;
// 操作栏弹出后调用
- (void)didPresentActionSheet:(UIActionSheet *)actionSheet NS_DEPRECATED_IOS(2_0, 8_3) __TVOS_PROHIBITED;
// 操作后将要隐藏的操作栏时调用
- (void)actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex NS_DEPRECATED_IOS(2_0, 8_3) __TVOS_PROHIBITED;
// 操作栏隐藏完成后调用
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex NS_DEPRECATED_IOS(2_0, 8_3) __TVOS_PROHIBITED; // after animation
@end
1
2
3
4
5
6
7
// 操作栏风格
typedef NS_ENUM(NSInteger, UIActionSheetStyle) {
UIActionSheetStyleAutomatic = -1, // take appearance from toolbar style otherwise uses 'default'
UIActionSheetStyleDefault = UIBarStyleDefault, // 默认
UIActionSheetStyleBlackTranslucent = UIBarStyleBlackTranslucent, // 半透明黑色
UIActionSheetStyleBlackOpaque = UIBarStyleBlackOpaque , // 不透明黑色
} __TVOS_PROHIBITED;