完全可定制的 UIActionSheet
替代品。兼容 iOS 7 和 8。
这个自定义 ActionSheet 也可以通过模糊演示视图的背景来强调与菜单相关的元素。本身元素仍然清晰。
以相同的方式初始化 UICustomActionSheet 对象,就像 UIActionSheet 一样
UICustomActionSheet *actionSheet = [[UICustomActionSheet alloc] initWithTitle:@"Hello World" delegate:self buttonTitles:@[@"Bottom button",@"Top button"]];
要在视图中呈现 UICustomActionSheet,您可以使用与 UIActionSheet 相同的方法
[actionSheet showInView:self.view];
为了处理 UICustomActionSheet 的事件,主控制器必须实现 UICustomActionSheetDelegate
的方法
-(void)customActionSheet:(UICustomActionSheet *)customActionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(@"%d",buttonIndex);
}
如果您不想在 ActionSheet 中显示标题,可以为 title
设置 nil
。执行您需要的任何自定义操作
-(void)setButtonColors:(NSArray *)colors
- 方法用于设置按钮颜色数组。如果 colors
数组包含的元素少于 UICustomActionSheet 中的按钮数量,则只有数组中的前 [colors count]
个按钮将被给定颜色,所有后续按钮将以 tintColor
(默认为 grayColor
)着色
-(void)setTitle:(NSString *)caption andSubtitle:(NSString *)subtitle
- 为 UICustomActionSheet 设置标题和副标题。这两个值默认为 nil
。
tintColor
- UICustomActionSheet 按钮的标准颜色
backgroundColor
- 面板背景颜色。使用 [UIColor clearColor]
值设置它以使其透明
titleColor
- UICustomActionSheet 标题的颜色。默认值为 whiteColor
subtitleColor
- UICustomActionSheet 副标题的颜色。默认值为 lightGrayColor
buttonsTextColor
- 普通状态下按钮的文本颜色。默认值为 whiteColor
subtitle
- 副标题文本。如果它是 nil
,则不会产生影响
subtitleFontSize
- 副标题文本字体大小 float
值。默认值为 14.0
title
- 主要标题文本。如果它是 nil
,则不会产生影响
titleFontSize
- 标题文本字体大 float
值。默认值为 22.0
blurredBackground
- bool
值。如果不想模糊 UICustomActionSheet 展示视图,则将其设置为 NO
。默认值为 YES
claerArea
- CGRect
值。当 blurredBackground = YES
时,接收到的 rect 不会被模糊处理。
MIT 许可协议 (MIT)
软件按“原样”提供,没有任何形式的保证,明示或暗示,包括但不限于适销性、特定用途适用性和非侵权性保证。在任何情况下,作者或版权所有者均不对任何索赔、损害或其他责任承担责任,无论这些责任是基于合同、侵权或其他方式,无论这些责任源于、与软件有关还是与之相关,或与软件的使用或其他交易有关。