Sagit. Framework For IOS development Framework getting started tutorial 5: Message pop-up window STMsgBox,
Preface:
Yesterday I wrote an IT connection entrepreneurship article: IT connection entrepreneurship series: Product Design Q & A module. (welcome to everyone !)
I feel that I haven't written an article on IOS for a long time. Today I am taking the opportunity to add a Sagit tutorial.
Sagit Open Source Address: https://github.com/cyq1162/Sagit
Today, we mainly share the message pop-up window function, that is, the usage of STMsgBox:
STMsgBox is the source code for pop-up window functions.
1. Description of calling external API functions:
The early pop-up window used to reference MBProgressHUD;
Later, I removed it and rewritten all the code in it.
APIS currently called externally:
Typedef BOOL (^ OnConfirmClick) (NSInteger btnIndex, UIAlertView * view); typedef BOOL (^ OnBeforeDialogHide) (UIView * winView, UIView * clickView); typedef void (^ OnBeforeShow) (UIAlertView * view); typedef void (^ OnDialogShow) (UIView * winView );//! Provides the basic message pop-up window @ interface STMsgBox: NSObject + (STMsgBox *) share; # pragma AlertView //! Prompt message-(void) prompt :( id) msg;-(void) prompt :( id) msg second :( NSInteger) second ;//! Pop up the message box (void) alert :( id) msg;-(void) alert :( id) msg title :( NSString *) title;-(void) alert :( id) msg title :( NSString *) title okText :( NSString *) okText;-(void) loading :( id) text;-(void) hideLoading; //! The message box for confirmation and event execution is displayed. -(Void) confirm :( id) msg title :( NSString *) title click :( OnConfirmClick) click;-(void) confirm :( id) msg title :( NSString *) title click :( OnConfirmClick) click okText :( NSString *) okText;-(void) confirm :( id) msg title :( NSString *) title click :( OnConfirmClick) click okText :( NSString *) okText cancelText :( NSString *) cancelText ;//! A dialog box (void) input :( id) title before :( OnBeforeShow) beforeShow click :( OnConfirmClick) click okText :( NSString *) is displayed *) okText cancelText :( NSString *) cancelText ;//! Dialog Box (void) dialog :( OnDialogShow) dialog;-(void) dialog :( OnDialogShow) dialog beforeHide :( OnBeforeDialogHide) beforeHide; @ end
2. Call Method
There are two methods for calling this class.
1. Use [self. msgBox...] directly under the Controller inherited from STController
The base class STController implements two sub-class interfaces by default (msgBox: pop-up message window, http: Network request)
For example:
[Self. msgBox prompt: @ "cannot be blank! "];
2. Global calls can be made anywhere: use [Sagit. MsgBox...]
Sagit is the initial namespace of A Class Library. Many common functions are started by opening the Sagit header.
For example:
[Sagit. MsgBox prompt: @ "blacklist added! "];
3. project code example
Next, we will share with you the Code related to IT connection apps:
A. prompt usage: When publishing A circle, A prompt is displayed.
-(Void) onRightNavBarClick :( UIBarButtonItem *) view {if (! [Self isMatch: @ "published content" name: @ "topic"]) {return;} NSString * jsonStr = [@ {@ "TopicContent ": STValue (@ "topic"), @ "photos": self. photos} toJson]; [self. http post: UrlTopicSet paras: @ {@ "topic": jsonStr} success: ^ (STModel * result) {if (result. success = YES) {[self. msgBox prompt: @ "published successfully! "]; [Self. preController reloadData]; [self stPop];} else {[self. msgBox prompt: result. msg] ;}}];}
Effect:
B. alert usage: indicates the penetration technique in little magic (explicit). If no parameter is set, the prompt is displayed.
-(Void) initUI {[super initUI]; [self loadScreenUI]; // Disable User-Defined images and display the self-defined penetrating images. userPhotos = nil; self. showSecond = 2; // read the set image self. penPhotos = Sagit. magic. setting. penPhotos; if (! Self. penPhotos | self. penPhotos. count = 0) {[self. msgBox alert: @ "set the penetration photo in the parameter settings first! "Title: @" message prompt "okText: @" I know "]; [self stPop]; return;} [self ready];}
Tip:
C. Usage of confirm: Save the image with a long press prompt
-(UIImageView *) save {[Sagit. MsgBox confirm: @ "do you want to save the image? "Title: @" message prompt "click: ^ BOOL (NSInteger isOK, UIAlertView * view) {if (isOK> 0) {[self. image save: ^ (NSError * err) {[Sagit. msgBox prompt :! Err? @ "Saved successfully": @ "failed to save: the permission to save the photo is denied. You need to reset it to save it! "];} Return YES;}]; return self ;}
Tip:
D. input usage: used to change the password
-(Void) updatePassword :( UITableViewCell *) cell {[[cell. textLabel text: @ "Change Password"] onClick: ^ (id view) {[self. msgBox input: @ "Change Password" before: ^ (UIAlertView * view) {view. alertViewStyle = custom; [[view textFieldAtIndex: 0] keyboardType: UIKeyboardTypeNumbersAndPunctuation];} click: ^ BOOL (NSInteger isOK, UIAlertView * view) {if (isOK> 0) {UITextField * text = [view textFieldAtIndex: 0]; if (! [Self isMatch: @ "password, in the format of 6-16 digits or letters" value: text. text regex: RexPassword]) {return NO;} [self. http post: UrlChangePwd paras: @ {@ "Password": text. text} success: ^ (STModel * result) {if (result. success) {[self. msgBox prompt: @ "Password Changed successfully"]; Sagit. global. token = (NSString *) result. msg;} else {[self. msgBox prompt: @ "failed to Change Password"] ;}}];} return YES;} okText: @ "Confirm Password" cancelText: @ "cancel"] ;}];}
Effect:
E. dialog usage. custom form: the usage of the sharing module is displayed.
-(Void) show :( alert model *) model after :( OnAfterShare) after beforeViewHide :( OnBeforeDialogHide) onBeforeViewHide {[Sagit. msgBox dialog: ^ (UIView * winView) {[[[[winView addUIView: nil] width: 1 height: 362] backgroundColor: DeviceColor] relate: Bottom v: 0] block: nil on: ^ (UIView * sView) {NSArray * uses imagearray = @ [@ "wechat2", @ "wechat", @ "qq", @ "qq2"]; NSArray * effectitlearray = @ [@ "friends", @ "friends", @ "QQ friends", @ "qqspace"]; for (int I = 0; I <shortimagearray. count; I ++) {UIImageView * imgView = [[[[sView addImageView: nil img: Hangzhou imagearray [I] width: 126 height: 126] relate: leftTop v :( 126 + 36) * I + 72 v2: 50] onClick: ^ (id view) {model. to = (ShareTo) I; [self send: model after: after]; [winView click]; // hide interface}]; [[[[sView addLabel: nil text: effectitlearray [I] font: 24 color: @ "#555555"] textAlignment: NSTextAlignmentCenter] width: 126] onBottom: imgView y: 22] onClick: ^ (id view) {[imgView click] ;}];} [[[[sView addUIView: nil] backgroundColor: ColorWhite] width: 1 height: 98] relate: Bottom v: 0] block: nil on: ^ (UIView * cancelView) {[[cancelView addLabel: nil text: @ "cancel" font: 32 color: ColorBlack] toCenter] ;}];}];} beforeHide: onBeforeViewHide];}
Effect:
F. dialog usage 2: difficulties in the Q & A pop-up
-(Void) show :( NSString *) type {[Sagit. msgBox dialog: ^ (UIView * winView) {[[[winView addImageView: nil img: @ "answer_pop"] width: 1 height: 814] toCenter] block: nil on: ^ (UIImageView * cView) {// beginner [[[cView addUIView: @ "level1"] width: 140 height: 62] relate: LeftTop v: 216 v2: 344] onClick: ^ (UIView * view) {[self showAnswerStart: winView questionType: type dificulty: @ "1"] ;}]; // intermediate [[[cView addUIView: @ "level2"] width: 140 height: 62] onRight: @ "level1" x: 42] onClick: ^ (UIView * view) {[self showAnswerStart: winView questionType: type dificulty: @ "2"];}]; // advanced [[[[cView addUIView: @ "level3"] width: 140 height: 62] onBottom: @ "level2" y: 60] toCenter: X] onClick: ^ (UIView * view) {[self showAnswerStart: winView questionType: type dificulty: @ "3"];}]; // question [[[cView addUIView: @ "level4"] width: 154 height: 154] relate: LeftTop v: 435 v2: 538] onClick: ^ (UIView * view) {[winView click]; ITWebViewController * wv = [ITWebViewController new]; NSString * url = [[UrlQuestionPost replace: @ "{uid}" with: Sagit. global. userID] replace: @ "{qt}" with: type]; [wv loadUrl: url]; NSString * qtName = [Sagit. global getConfigKey: @ "Answer type" value: type]; wv. defaultTitle = STString (@ "my question: % @", qtName); wv. denyChangeTitle = YES; [self stPush: wv];}-(void) showAnswerStart :( UIView *) view questionType :( NSString *) type dificulty :( NSString *) dificulty {AnswerModel * model = [AnswerModel new]; model. score = 0; model. startTime = [NSDate. beiJinDate toString]; model. answerCount = 1; model. questionType = type. integerValue; model. questionDifficulty = dificulty. integerValue; UIViewController * con = [STNew (@ "AnswerStart") key: @ "answerModel" value: model]; [self stPush: con title: nil img: nil]; [view click];}
Effect:
Summary:
Although this article introduces the pop-up message, the shared code is a complete functional module in the IT connection.
If you scan the code carefully, you can see that it is concise to write code using the Sagit framework.
Sagit framework makes IOS development easier. You have the value !!!