由于我需要更多的自定义和不同的外观,因此我创建了这个 UIActionSheet 的小型替代品。
#Cocoapods
pod 'WCActionSheet'
#Of course you can also download the source and copy the WCActionSheet.* and UIImage+ImageEffect.* files.
我将 API 设计得尽可能相似于 UIActionSheet。
// With this initializer, you are responsible for adding buttons. Standard cancel button is added for you.
WCActionSheet *actionSheet = [[WCActionSheet alloc] init];
// Equivalent to -init. Frame argument is not taken into consideration
WCActionSheet *actionSheet = [[WCActionSheet alloc] initWithFrame:aframe];
// Designed initializer. Similar to UIActionSheet's one.
WCActionSheet *actionSheet = [[WCActionSheet alloc] initWithFrame:initWithDelegate:delegate cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Button !", @"Button 2", nil];
// Adding buttons with action block. This won't fire delegate call -actionSheet:clickedButtonAtIndex
[actionSheet addButtonWithTitle:@"Hi!" actionBlock:^{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Hi!" message:@"My name is Wojtek and I made it" delegate:nil cancelButtonTitle:@"okay" otherButtonTitles: nil];
[alert show];
}];
// Adding buttons without action block. (This one, when tapped, will fire delegate call.
[actionSheet addButtonWithTitle:@"Bye"];
// Showing WCActionSheet is as simple as:
[actionSheet show];
@protocol WCActionSheetDelegate <NSObject>
@optional
// Called when a button is clicked. The view will be automatically dismissed after this call returns
- (void)actionSheet:(WCActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex;
// Called when we cancel a view (eg. the user clicks the Home button). This is not called when the user clicks the cancel button.
// If not defined in the delegate, we simulate a click in the cancel button
- (void)actionSheetCancel:(WCActionSheet *)actionSheet;
- (void)willPresentActionSheet:(WCActionSheet *)actionSheet; // before animation and showing view
- (void)didPresentActionSheet:(WCActionSheet *)actionSheet; // after animation
- (void)actionSheet:(WCActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex; // before animation and hiding view
- (void)actionSheet:(WCActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex; // after animation
@end
// You may use UIAppearance proxy in order to set following properties. (You can also set the properties directly)
@property(nonatomic) CGFloat blurRadius UI_APPEARANCE_SELECTOR;
@property(nonatomic, strong) UIColor *blurTintColor UI_APPEARANCE_SELECTOR;
@property(nonatomic, strong) UIColor *separatorColor UI_APPEARANCE_SELECTOR;
@property(nonatomic, strong) UIColor *highlightedButtonColor UI_APPEARANCE_SELECTOR;
- (NSDictionary *)buttonTextAttributesForState:(UIControlState)state UI_APPEARANCE_SELECTOR;
- (void)setButtonTextAttributes:(NSDictionary *)attributes forState:(UIControlState)state UI_APPEARANCE_SELECTOR;
- (NSDictionary *)cancelButtonTextAttributesForState:(UIControlState)state UI_APPEARANCE_SELECTOR;
- (void)setCancelButtonTextAttributes:(NSDictionary *)attributes forState:(UIControlState)state UI_APPEARANCE_SELECTOR;
- (NSDictionary *)destructiveButtonTextAttributesForState:(UIControlState)state UI_APPEARANCE_SELECTOR;
- (void)setDestructiveButtonTextAttributes:(NSDictionary *)attributes forState:(UIControlState)state UI_APPEARANCE_SELECTOR;
WCActionSheet 遵循 MIT 许可证。
您可以在 twitter @wczekalski 或通过 给我写信 联系我,如果您感觉友好