中文介绍
A basic Pop-Up Kit allows you to easily create Pop-Up view. You can focus on the only view you want to show.
Besides, it comes with 2 common Pop-Up view, MMAlertView & MMSheetView. You can easily use & customize it.
or you can check the demo video below(click the image).
Installation
The preferred way of installation is via CocoaPods. Just add
pod 'MMPopupView'
and run pod install
. It will install the most recent version of MMPopupView.
If you would like to use the latest code of MMPopupView use:
pod 'MMPopupView', :head
Usage
NSArray *items =
@[MMItemMake(@"Done", MMItemTypeNormal, block),
MMItemMake(@"Save", MMItemTypeHighlight, block),
MMItemMake(@"Cancel", MMItemTypeNormal, block)];
[[[MMAlertView alloc] initWithTitle:@"AlertView"
detail:@"each button take one row if there are more than 2 items"
items:items]
showWithBlock:completeBlock];
NSArray *items =
@[MMItemMake(@"Normal", MMItemTypeNormal, block),
MMItemMake(@"Highlight", MMItemTypeHighlight, block),
MMItemMake(@"Disabled", MMItemTypeDisabled, block)];
[[[MMSheetView alloc] initWithTitle:@"SheetView"
items:items] showWithBlock:completeBlock];
MMPopupView is a basic Pop-Up view designed to be subclassed.
It provide 3 kind of animations(alert, sheet, drop), or you can provide your own animation by override the showAnimation and hideAnimation.
typedef NS_ENUM(NSUInteger, MMPopupType) {
MMPopupTypeAlert,
MMPopupTypeSheet,
MMPopupTypeCustom,
};
@class MMPopupView;
typedef void(^MMPopupBlock)(MMPopupView *);
typedef void(^MMPopupCompletionBlock)(MMPopupView *, BOOL);
@interface MMPopupView : UIView
@property (nonatomic, assign, readonly) BOOL visible;
@property (nonatomic, strong ) UIView *attachedView;
@property (nonatomic, assign ) MMPopupType type;
@property (nonatomic, assign ) NSTimeInterval animationDuration;
@property (nonatomic, assign ) BOOL withKeyboard;
@property (nonatomic, copy ) MMPopupCompletionBlock showCompletionBlock;
@property (nonatomic, copy ) MMPopupCompletionBlock hideCompletionBlock;
@property (nonatomic, copy ) MMPopupBlock showAnimation;
@property (nonatomic, copy ) MMPopupBlock hideAnimation;
- (void) showKeyboard;
- (void) hideKeyboard;
- (void) show;
- (void) showWithBlock:(MMPopupBlock)block;
- (void) hide;
- (void) hideWithBlock:(MMPopupBlock)block;
@end
+ (void) hideAll;
If you want to create your own Pop-Up view,simply you only need to subclass from MMPopupView.
@interface YourCustomView : MMPopupView
@end
after you customize it, you can simply use it.
[YourCustomView show];
[YourCustomView showWithBlock:completionBlock];
[YourCustomView hide];
[YourCustomView hideWithBlock:completionBlock];
MMAlertView
MMAlertView is based on MMPopupView.
typedef void(^MMPopupInputHandler)(NSString *text);
@interface MMAlertView : MMPopupView
@property (nonatomic, assign) NSUInteger maxInputLength;
- (instancetype) initWithInputTitle:(NSString*)title
detail:(NSString*)detail
placeholder:(NSString*)inputPlaceholder
handler:(MMPopupInputHandler)inputHandler;
- (instancetype) initWithConfirmTitle:(NSString*)title
detail:(NSString*)detail;
- (instancetype) initWithTitle:(NSString*)title
detail:(NSString*)detail
items:(NSArray*)items;
@end
MMAlertViewConfig is the global configuration of MMAlertView, you can fully customize by adjust it.
@interface MMAlertViewConfig : NSObject
+ (MMAlertViewConfig*) globalConfig;
@property (nonatomic, assign) CGFloat width;
@property (nonatomic, assign) CGFloat buttonHeight;
@property (nonatomic, assign) CGFloat innerMargin;
@property (nonatomic, assign) CGFloat cornerRadius;
@property (nonatomic, assign) CGFloat titleFontSize;
@property (nonatomic, assign) CGFloat detailFontSize;
@property (nonatomic, assign) CGFloat buttonFontSize;
@property (nonatomic, strong) UIColor *backgroundColor;
@property (nonatomic, strong) UIColor *titleColor;
@property (nonatomic, strong) UIColor *detailColor;
@property (nonatomic, strong) UIColor *splitColor;
@property (nonatomic, strong) UIColor *itemNormalColor;
@property (nonatomic, strong) UIColor *itemHighlightColor;
@property (nonatomic, strong) UIColor *itemPressedColor;
@property (nonatomic, strong) NSString *defaultTextOK;
@property (nonatomic, strong) NSString *defaultTextCancel;
@property (nonatomic, strong) NSString *defaultTextConfirm;
@end
MMSheetView
MMSheetView is based on MMPopupView.
@interface MMSheetView : MMPopupView
- (instancetype) initWithTitle:(NSString*)title
items:(NSArray*)items;
@end
MMSheetViewConfig is the global configuration of MMAlertView, you can fully customize by adjust it.
@interface MMSheetViewConfig : NSObject
+ (MMSheetViewConfig*) globalConfig;
@property (nonatomic, assign) CGFloat buttonHeight;
@property (nonatomic, assign) CGFloat innerMargin;
@property (nonatomic, assign) CGFloat titleFontSize;
@property (nonatomic, assign) CGFloat buttonFontSize;
@property (nonatomic, strong) UIColor *backgroundColor;
@property (nonatomic, strong) UIColor *titleColor;
@property (nonatomic, strong) UIColor *splitColor;
@property (nonatomic, strong) UIColor *itemNormalColor;
@property (nonatomic, strong) UIColor *itemDisableColor;
@property (nonatomic, strong) UIColor *itemHighlightColor;
@property (nonatomic, strong) UIColor *itemPressedColor;
@property (nonatomic, strong) NSString *defaultTextCancel;
@end
Changelog
v1.7.1 Fix black screen problem when attachView is the main keyWindow.
v1.7 Add blur effect.
@interface UIView (MMPopup)
@property (nonatomic, strong, readonly ) UIView *mm_dimBackgroundBlurView;
@property (nonatomic, assign ) BOOL mm_dimBackgroundBlurEnabled;
@property (nonatomic, assign ) UIBlurEffectStyle mm_dimBackgroundBlurEffectStyle;
@end
e.g.
alertView.attachedView = self.view;
alertView.attachedView.mm_dimBackgroundBlurEnabled = YES;
alertView.attachedView.mm_dimBackgroundBlurEffectStyle = UIBlurEffectStyleLight;
v1.6 Add '+ hideAll' method, improve code struct.
v1.5.3 Fixed touch problem with touchWildToHide
v1.5.2 Fixed touch problem when there are scrollviews in custom view
v1.5.1 Fixed showing problem
v1.5 Fixed rotation problem
v1.4 Adjust animation easing function. Rebuild the demo.(thx to @yoavlt)
v1.3 Bug fixed
v1.2 Now you could know whether MMPopupView is visible by using:
@property (nonatomic, assign, readonly) BOOL visible; // default is NO.
v1.1 Now you can attached MMPopupView to any UIView you want by using:
@property (nonatomic, strong ) UIView *attachedView;
v1.0 first version