How to write a custom Alertview
Effect
Description
Considering the subsequent customization and maintainability, I have defined the base class of Alertview abstraction with Abstractalertview, which is accomplished by subclasses.
Note: This is just a rough write of an implementation, and does not take into account the rationality of the Code and accuracy.
Source
Https://github.com/YouXianMing/AbstractAlertView
////AbstractAlertView.h//Alertviewdemo////Created by youxianming on 15/10/15.//copyright©2015 year Zipeiyi. All rights reserved.//#import<UIKit/UIKit.h>@classAbstractalertview;@protocolAlertvieweventdelegate <NSObject>@required/** * Event executed by Agent * * @param alertview Alertview * @param index button number*/- (void) Alertview: (Abstractalertview *) Alertview Buttoneventindex: (nsinteger) index;@end@interfaceAbstractalertview:uiview/** * Responding to Event agents*/@property (nonatomic, weak)ID<AlertViewEventDelegate>Delegate;/** * The view displayed after inserting*/@property (nonatomic, weak) UIView*Insertview;/** * Title*/@property (nonatomic, strong) NSString*title;/** * Subtitle*/@property (nonatomic, strong) NSString*SubTitle;/** * Information*/@property (nonatomic, strong) NSString*message;/** * Button header array*/@property (nonatomic, strong) Nsarray<nsstring *> *Buttontitlesarray;/** * Display (build a view at show)*/- (void) show;/** * Hide*/- (void) Hide;@end
////abstractalertview.m//Alertviewdemo////Created by youxianming on 15/10/15.//copyright©2015 year Zipeiyi. All rights reserved.//#import "AbstractAlertView.h"@implementationAbstractalertview- (void) Show {}- (void) Hide {}@end
Details
How to write a custom Alertview