#import "HMViewController.h"#import "HMQuestion.h"#defineKbuttonwidth 35#defineKbuttonheight 35#defineKbuttonmargin 10#defineKtotolcol 7@interfaceHmviewcontroller () @property (weak, nonatomic) Iboutlet UIButton*Iconbutton, @property (weak, nonatomic) Iboutlet UILabel*Nolabel, @property (weak, nonatomic) Iboutlet UILabel*Titlelabel, @property (weak, nonatomic) Iboutlet UIButton*Nextquestionbutton, @property (weak, nonatomic) Iboutlet UIView*answerview;//Answer Box@property (Weak, nonatomic) Iboutlet UIView *optionsview;//selection Box@property (nonatomic, strong) Nsarray *questions;//Data/** Topic Index*/@property (nonatomic, assign)intindex;@end@implementationHmviewcontroller-(Nsarray *) questions{if(_questions = =Nil) {_questions=[hmquestion questions]; } return_questions;}-(UIButton *) cover{if(_cover = =Nil) {_cover=[[UIButton alloc] initWithFrame:self.view.bounds]; _cover.backgroundcolor= [Uicolor colorwithwhite:0.0Alpha0.5]; [Self.view Addsubview:_cover]; _cover.alpha=0.0; [_cover addtarget:self Action: @selector (Bigimage) forcontrolevents:uicontroleventtouchupinside]; } return_cover;}- (void) viewdidload{[Super Viewdidload]; Self.index= -1; [Self nextquestion];}/** Adjust status bar color*//** Uistatusbarstyledefault black status bar uistatusbarstylelightcontent bright status bar*/-(uistatusbarstyle) preferredstatusbarstyle{returnuistatusbarstylelightcontent;} #pragmaMark-Next question-(ibaction) nextquestion{//1. Index of current answer, index incrementself.index++; //2. Remove the problem model data from the array by indexHmquestion *question =Self.questions[self.index]; //3. Setting up basic informationSelf.noLabel.text = [NSString stringWithFormat:@"%d/%d", Self.index +1, Self.questions.count]; Self.titleLabel.text=Question.title; [Self.iconbutton setimage:[uiimage ImageNamed:question.icon] forstate:uicontrolstatenormal]; //If the last question is reached, disable the Next buttonself.nextQuestionButton.enabled = (Self.index < Self.questions.count-1); //4. Set Answer button//First Erase all buttons in the answer area//all controls are inherited from UIView, polymorphic applications for(UIView *btninchself.answerView.subviews) {[btn Removefromsuperview]; } cgfloat answerw=Self.answerView.bounds.size.width; intLength =question.answer.length; CGFloat Answerx= (Answerw-kbuttonwidth * length-kbuttonmargin * (Length-1)) *0.5; //Create a button for all answers for(inti =0; i < length; i++) {cgfloat x= Answerx + I * (Kbuttonmargin +kbuttonwidth); UIButton*BTN = [[UIButton alloc] Initwithframe:cgrectmake (x,0, Kbuttonwidth, Kbuttonheight)]; [Btn setbackgroundimage:[uiimage imagenamed:@"Btn_answer"] Forstate:uicontrolstatenormal]; [Btn setbackgroundimage:[uiimage imagenamed:@"btn_answer_highlighted"] forstate:uicontrolstatehighlighted]; [Self.answerview ADDSUBVIEW:BTN]; } //5. Set the alternate button for(UIView *viewinchself.optionsView.subviews) {[View Removefromsuperview]; } cgfloat optionw=Self.optionsView.bounds.size.width; CGFloat Optionx= (Optionw-ktotolcol * kbuttonwidth-(Ktotolcol-1) * kbuttonmargin) *0.5; for(inti =0; i < Question.options.count; i++) { introw = I/Ktotolcol; intCol = i%Ktotolcol; CGFloat x= Optionx + col * (Kbuttonmargin +kbuttonwidth); CGFloat y= Row * (Kbuttonmargin +kbuttonheight); UIButton*BTN =[[UIButton alloc] Initwithframe:cgrectmake (x, Y, Kbuttonwidth, kbuttonheight)]; [Btn setbackgroundimage:[uiimage imagenamed:@"btn_option"] Forstate:uicontrolstatenormal]; [Btn setbackgroundimage:[uiimage imagenamed:@"btn_option_highlighted"] forstate:uicontrolstatehighlighted]; //Set Alternate answers[btn Settitle:question.options[i] forstate:uicontrolstatenormal]; [btn Settitlecolor:[uicolor Blackcolor] forstate:uicontrolstatenormal]; [Self.optionsview ADDSUBVIEW:BTN]; } NSLog (@"%d", Self.optionsView.subviews.count);}@end
iOS fourth day (4: Implementation of the next question and marquee)