LBActionSheet 是 UIActionSheet 的直接替代品。然而,其 API 使得自定义变得非常简单。它只为这个单一目的而设计,这使得在不需要实现自定义主题时变得多余。
LBActionSheet 的 API 几乎与 UIActionSheet 相同。虽然它可能在未来有所改变,但你仍然应该去熟悉它。
LBActionsSheet
文件夹拖放到您的项目中。CoreImage.framework
。LBActionSheet* sheet = [[LBActionSheet alloc] initWithTitle:@"Discard?" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Discard" otherButtonTitles:@"Save as draft", nil]; [sheet setDefaultButtonBackgroundImage:[[UIImage imageNamed:@"actionsheet-button"] stretchableImageWithLeftCapWidth:7 topCapHeight:0] forState:UIControlStateNormal];
[sheet setDefaultButtonBackgroundImage:[[UIImage imageNamed:@"actionsheet-button-pressed"] stretchableImageWithLeftCapWidth:7 topCapHeight:0] forState:UIControlStateHighlighted];
sheet.backgroundImage = [UIImage imageNamed:@"actionsheet-background"];
NSMutableDictionary* titleAttributes = [NSMutableDictionary new];
[titleAttributes setObject:[UIFont fontWithName:@"HelveticaNeue-Bold" size:24.0f] forKey:UITextAttributeFont];
[titleAttributes setObject:[UIColor whiteColor] forKey:UITextAttributeTextColor];
[titleAttributes setObject:[UIColor colorWithWhite:0.0f alpha:0.5f] forKey:UITextAttributeTextShadowColor];
[titleAttributes setObject:[NSValue valueWithCGSize:CGSizeMake(0.0f, 1.0f)] forKey:UITextAttributeTextShadowOffset];
[sheet setButtonTitleAttributes:titleAttributes forState:UIControlStateNormal];
[sheet setButtonTitleAttributes:titleAttributes forState:UIControlStateHighlighted];
UIImageView* separator = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, CGRectGetWidth([UIScreen mainScreen].applicationFrame), 3.0f)];
separator.image = [UIImage imageNamed:@"actionsheet-separator"];
[sheet insertControl:separator atIndex:self.cancelButtonIndex];
[sheet showInView:self.view];
ARC。
LBActionSheet 使用的是 MIT 许可证。