add message exercises
This commit is contained in:
@@ -15,6 +15,9 @@
|
||||
#import "UIView+Toast.h"
|
||||
#import "GiGaMeViewController.h"
|
||||
#import "GiGaAdDetailViewController.h"
|
||||
#import "GiGaMasssagesVC.h"
|
||||
#import "Masonry.h"
|
||||
#import "GiGaQuestionVC.h"
|
||||
|
||||
@interface GiGaMaskTaskViewController ()
|
||||
@property(nonatomic,strong)MaskViewBootomWaringView *waringView;
|
||||
@@ -26,12 +29,46 @@
|
||||
[super viewDidLoad];
|
||||
// Do any additional setup after loading the view.
|
||||
[self setUpNav];
|
||||
[self initUI];
|
||||
[self addNotify];
|
||||
BOOL canshowGaurd = [GiGaUserDefault isShowedGaurd];
|
||||
if (!canshowGaurd) {
|
||||
NSLog(@"%d",(int)canshowGaurd );
|
||||
}
|
||||
|
||||
-(void)initUI{
|
||||
|
||||
UIButton *testBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
[testBtn setTitle:@"测试肤质" forState:UIControlStateNormal];
|
||||
[testBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
||||
testBtn.backgroundColor = [UIColor blueColor];
|
||||
[testBtn addTarget:self action:@selector(testBtnAcion:) forControlEvents:UIControlEventTouchUpInside];
|
||||
testBtn.layer.masksToBounds = YES;
|
||||
testBtn.layer.cornerRadius = 4;
|
||||
|
||||
[self.view addSubview:testBtn];
|
||||
[testBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.centerX.mas_equalTo(self.view.mas_centerX);
|
||||
make.width.mas_equalTo(150);
|
||||
make.height.mas_equalTo(40);
|
||||
make.bottom.mas_equalTo(self.view.mas_bottom).offset(-200);
|
||||
}];
|
||||
|
||||
}
|
||||
|
||||
#pragma mark 开始测试
|
||||
-(void)testBtnAcion:(UIButton *)btn{
|
||||
|
||||
BOOL isUserLogin = [GiGaUserDefault isUserLogin];
|
||||
if (isUserLogin) {
|
||||
|
||||
//GIGA_ShowToast(@"userLogin!");
|
||||
GiGaQuestionVC *questionVC = [[GiGaQuestionVC alloc] init];
|
||||
[self.navigationController pushViewController:questionVC animated:YES];
|
||||
|
||||
}else{
|
||||
GiGaUserLoginVC *userlogInVC= [[GiGaUserLoginVC alloc] init];
|
||||
GiGaBaseNavViewController *baseNav = [[GiGaBaseNavViewController alloc] initWithRootViewController:userlogInVC];
|
||||
[self presentViewController:baseNav animated:YES completion:nil];
|
||||
}
|
||||
// NSLog(@"%d",(int)canshowGaurd );
|
||||
|
||||
}
|
||||
|
||||
-(void)viewDidAppear:(BOOL)animated{
|
||||
@@ -58,10 +95,12 @@
|
||||
[self.navigationController pushViewController:detailVC animated:YES];
|
||||
|
||||
}
|
||||
|
||||
#pragma mark 新手引导消失
|
||||
-(void)guardViewDissmiss{
|
||||
[self showWaringView];
|
||||
}
|
||||
|
||||
#pragma mark app引导页消失
|
||||
-(void)appGauardViewDissmiss{
|
||||
//出现新手引导
|
||||
@@ -71,6 +110,7 @@
|
||||
[self showUserGaurdView];
|
||||
}
|
||||
}
|
||||
|
||||
-(void)dealloc{
|
||||
|
||||
NC_REMOVE_NAME(self, USER_GUARD_DISSMISS, nil);
|
||||
@@ -120,9 +160,11 @@
|
||||
-(void)leftBtnAction{
|
||||
BOOL isUserLogin = [GiGaUserDefault isUserLogin];
|
||||
if (isUserLogin) {
|
||||
|
||||
GIGA_ShowToast(@"userLogin!");
|
||||
|
||||
|
||||
GiGaMasssagesVC *masageVC= [[GiGaMasssagesVC alloc] init];
|
||||
[self.navigationController pushViewController:masageVC animated:YES];
|
||||
|
||||
}else{
|
||||
GiGaUserLoginVC *userlogInVC= [[GiGaUserLoginVC alloc] init];
|
||||
GiGaBaseNavViewController *baseNav = [[GiGaBaseNavViewController alloc] initWithRootViewController:userlogInVC];
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
//
|
||||
// GiGaQuestionVC.h
|
||||
// GIGA
|
||||
//
|
||||
// Created by lianxiang on 2018/8/23.
|
||||
// Copyright © 2018年 com.giga.ios. All rights reserved.
|
||||
//
|
||||
|
||||
#import "GiGaBaseViewController.h"
|
||||
|
||||
@interface GiGaQuestionVC : GiGaBaseViewController
|
||||
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,189 @@
|
||||
//
|
||||
// GiGaQuestionVC.m
|
||||
// GIGA
|
||||
//
|
||||
// Created by lianxiang on 2018/8/23.
|
||||
// Copyright © 2018年 com.giga.ios. All rights reserved.
|
||||
//
|
||||
|
||||
#import "GiGaQuestionVC.h"
|
||||
#import "GIGAQuetionView.h"
|
||||
#import "GiGaQuestionModel.h"
|
||||
#import "Masonry.h"
|
||||
|
||||
@interface GiGaQuestionVC ()
|
||||
|
||||
@property (nonatomic,weak) GIGAQuetionView *questionView;
|
||||
@property (nonatomic,assign) NSInteger page;
|
||||
@property (nonatomic,strong) NSMutableArray *questonArray;
|
||||
@property (nonatomic,strong) GiGaQuestionModel *currentModel;
|
||||
@property (nonatomic,strong) UILabel *questionlabel;
|
||||
@property (nonatomic,strong) UIButton *nextBtn;
|
||||
@end
|
||||
|
||||
@implementation GiGaQuestionVC
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[self addNavTitile:@"测试肤质"];
|
||||
[super viewDidLoad];
|
||||
// self.title = @"测试肤质";
|
||||
_page = 1;
|
||||
//模拟服务器数据
|
||||
[self initControls];
|
||||
[self setquestionArray];
|
||||
[self getQuestionsInfo];
|
||||
|
||||
}
|
||||
|
||||
-(NSMutableArray *)questonArray{
|
||||
if (!_questonArray) {
|
||||
_questonArray = [[NSMutableArray alloc] init];
|
||||
}
|
||||
return _questonArray;
|
||||
}
|
||||
|
||||
-(void)setquestionArray{
|
||||
NSArray *array = @[
|
||||
@{@"questionid" : @"1", @"totalCount" : @"5", @"question" : @"如果昨天是明天的话就好了,这样今天就周五了。真实的今天可能是星期几?", @"questiontype" : @"1", @"questiontype_text" : @"单选题", @"questionselectnumber" : @"3", @"questiondescribe" : @"星期三:理想今天是星期五,昨天是星期四,真实明天是理想的昨天是星期四,真实的今天是星期三。\n星期日:理想今天是星期五,明天是星期六,真实昨天是理想的明天是星期六,真实的今天是星期日。", @"trueanswer" : @"A", @"userAnswer" : @[], @"tkselect" : @[@"A:星期三", @"B:星期四", @"C:星期五"]},
|
||||
@{@"questionid" : @"2", @"totalCount" : @"5", @"question" : @"这里是问题,这道题的答案是AC。这里是问题,这道题的答案是AC。这里是问题,这道题的答案是AC。", @"questiontype" : @"1", @"questiontype_text" : @"多选题", @"questionselectnumber" : @"5", @"questiondescribe" : @"这里是答案解析,这里可以很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长的。", @"trueanswer" : @"AC", @"userAnswer" : @[], @"tkselect" : @[@"A:这个选项是正确的。这个选项是正确的。这个选项是正确的。", @"B:这个选项是错误的。这个选项是错误的。这个选项是错误的。", @"C:这个选项是正确的。这个选项是正确的。这个选项是正确的。", @"D:这个选项是错误的。这个选项是错误的。这个选项是错误的。", @"E:这个选项是错误的。这个选项是错误的。这个选项是错误的。"]},
|
||||
@{@"questionid" : @"3", @"totalCount" : @"5", @"question" : @"以下哪个牌子不是化妆品?", @"questiontype" : @"1", @"questiontype_text" : @"单选题", @"questionselectnumber" : @"3", @"questiondescribe" : @"化妆品,化妆品化妆品化妆品化妆品化妆品化妆品化妆品。", @"trueanswer" : @"A", @"userAnswer" : @[], @"tkselect" : @[@"A:化妆品", @"B:化妆品", @"C:星期五"]},
|
||||
@{@"questionid" : @"4", @"totalCount" : @"5", @"question" : @"如果昨天是明天的话就好了,这样今天就周五了。真实的今天可能是星期几?", @"questiontype" : @"1", @"questiontype_text" : @"单选题", @"questionselectnumber" : @"3", @"questiondescribe" : @"真实昨天是理想的明天是星期六,真实的今天是星期日?", @"trueanswer" : @"A", @"userAnswer" : @[], @"tkselect" : @[@"A:星三", @"B:星", @"C:期"]},
|
||||
@{@"questionid" : @"5", @"totalCount" : @"5", @"question" : @"星期几?", @"questiontype" : @"1", @"questiontype_text" : @"单选题", @"questionselectnumber" : @"3", @"questiondescribe" : @"星期三:理想今天是星期五,昨天是星期四,真实明天是理想的昨天是星期四,真实的今天是星期三。\n星期日:理想今天是星期五,明天是星期六,真实昨天是理想的明天是星期六,真实的今天是星期日。", @"trueanswer" : @"A", @"userAnswer" : @[], @"tkselect" : @[@"A:三", @"B:四", @"C:五"]},
|
||||
|
||||
];
|
||||
for (NSDictionary *dic in array) {
|
||||
GiGaQuestionModel *model = [[GiGaQuestionModel alloc] initWithDictionary:dic error:nil];
|
||||
[self.questonArray addObject:model];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#pragma mark 获取当前题目信息
|
||||
-(void)getQuestionsInfo{
|
||||
|
||||
_currentModel = _questonArray[_page - 1];
|
||||
|
||||
[self reloadViews];
|
||||
}
|
||||
|
||||
#pragma mark 刷新题目
|
||||
-(void)reloadViews{
|
||||
//刷新问题相关数据
|
||||
NSString *questionlabelText = [NSString stringWithFormat:@"%@.%@", _currentModel.questionid, _currentModel.question];
|
||||
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
|
||||
[paragraphStyle setLineSpacing:4.0f];
|
||||
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:questionlabelText];
|
||||
NSDictionary *attrs =@{NSFontAttributeName:[UIFont systemFontOfSize:18]};
|
||||
[attributedString setAttributes:attrs range:NSMakeRange(0, 2)];
|
||||
|
||||
_questionlabel.attributedText = attributedString;
|
||||
|
||||
[self.view layoutIfNeeded];//必加
|
||||
//刷新答案相关数据
|
||||
[_questionView reloadViewWithFrame:CGRectMake(0, CGRectGetMaxY(_questionlabel.frame) + 15, KMainW, 0) style:[_currentModel.questiontype intValue] - 1 answerArray:_currentModel.tkselect userAnswers:_currentModel.userAnswer];
|
||||
|
||||
|
||||
}
|
||||
|
||||
#pragma mark 创建控件
|
||||
-(void)initControls{
|
||||
|
||||
//顶部
|
||||
UIImageView *topBackImagiew = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@""]];
|
||||
topBackImagiew.backgroundColor = [UIColor lightGrayColor];
|
||||
[self.view addSubview:topBackImagiew];
|
||||
|
||||
[topBackImagiew mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.width.mas_equalTo(KMainW - 30*2);
|
||||
make.height.mas_equalTo(140);
|
||||
make.top.mas_equalTo(self.view.mas_top).offset(100);
|
||||
make.left.mas_equalTo(self.view.mas_left).offset(30);
|
||||
}];
|
||||
UILabel *desLabel = [[UILabel alloc] init];
|
||||
desLabel.text = @"通过测试可以得知您是什么肤质,有助于选择更适合的面膜";
|
||||
desLabel.font = [UIFont systemFontOfSize:22];
|
||||
desLabel.numberOfLines = 0;
|
||||
[desLabel sizeToFit];
|
||||
[topBackImagiew addSubview:desLabel];
|
||||
[desLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.center.mas_equalTo(topBackImagiew.center);
|
||||
make.width.mas_equalTo(KMainW - 30*2 - 20*2);
|
||||
|
||||
}];
|
||||
|
||||
//问题标签
|
||||
UILabel *questionLabel = [[UILabel alloc] init];
|
||||
questionLabel.textColor = GIGAUIColorFromRGBA(0x292929);
|
||||
questionLabel.font = [UIFont systemFontOfSize:15.f];
|
||||
questionLabel.numberOfLines = 0;
|
||||
[self.view addSubview:questionLabel];
|
||||
self.questionlabel = questionLabel;
|
||||
[self.questionlabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(self.view.mas_left).offset(30);
|
||||
make.top.mas_equalTo(topBackImagiew.mas_bottom).offset(10);
|
||||
make.right.mas_equalTo(self.view.mas_right).offset(-30);
|
||||
|
||||
}];
|
||||
|
||||
//选择题view
|
||||
GIGAQuetionView *questionView = [[GIGAQuetionView alloc] init];
|
||||
questionView.backgroundColor = [UIColor lightGrayColor];
|
||||
[self.view addSubview:questionView];
|
||||
self.questionView = questionView;
|
||||
// [self.questionView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
// make.top.mas_equalTo(self.questionlabel.mas_bottom).offset(10);
|
||||
// make.height.mas_equalTo(0);
|
||||
// make.left.mas_equalTo(self.view.mas_left).offset(30);
|
||||
// make.right.mas_equalTo(self.view.mas_right).offset(-30);
|
||||
// }];
|
||||
|
||||
//下一题
|
||||
UIButton *nextBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
nextBtn.backgroundColor = [UIColor purpleColor];
|
||||
[nextBtn setTitle:@"下一个" forState:UIControlStateNormal];
|
||||
[nextBtn addTarget:self action:@selector(nextBtnAction) forControlEvents:UIControlEventTouchUpInside];
|
||||
nextBtn.layer.masksToBounds = YES;
|
||||
nextBtn.layer.cornerRadius = 2;
|
||||
[self.view addSubview:nextBtn];
|
||||
self.nextBtn = nextBtn;
|
||||
|
||||
|
||||
[nextBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.bottom.mas_equalTo(self.view.mas_bottom).offset(-100);
|
||||
make.width.mas_equalTo(160);
|
||||
make.height.mas_equalTo(40);
|
||||
make.centerX.mas_equalTo(self.view.mas_centerX);
|
||||
}];
|
||||
|
||||
}
|
||||
|
||||
-(void)nextBtnAction{
|
||||
if (_page == [_currentModel.totalCount integerValue] ) {
|
||||
GIGA_ShowToast(@"没有了");
|
||||
return;
|
||||
}
|
||||
[self saveProgress];
|
||||
_page ++ ;
|
||||
//获取题目信息
|
||||
[self getQuestionsInfo];
|
||||
|
||||
//self.nextBtn.enabled = _page == [_currentModel.totalCount integerValue] ? NO : YES;
|
||||
|
||||
}
|
||||
|
||||
#pragma mark -做题记录
|
||||
-(void)saveProgress{
|
||||
NSString *answer = self.questionView.selectAnswer;
|
||||
NSString *anserNum = self.questionView.qrnum;
|
||||
NSString *anserid = _currentModel.questionid;
|
||||
GILog(@"选择答案:%@\n 角标:%@\n 题号:%@",answer,anserNum,anserid);
|
||||
}
|
||||
|
||||
- (void)didReceiveMemoryWarning {
|
||||
[super didReceiveMemoryWarning];
|
||||
// Dispose of any resources that can be recreated.
|
||||
}
|
||||
|
||||
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,43 @@
|
||||
//
|
||||
// GiGaQuestionModel.h
|
||||
// GIGA
|
||||
//
|
||||
// Created by lianxiang on 2018/8/23.
|
||||
// Copyright © 2018年 com.giga.ios. All rights reserved.
|
||||
//
|
||||
|
||||
#import <JSONModel/JSONModel.h>
|
||||
|
||||
@interface GiGaQuestionModel : JSONModel
|
||||
|
||||
//统计题数总量
|
||||
@property (nonatomic, copy) NSString *totalCount;
|
||||
|
||||
//试题id
|
||||
@property (nonatomic, copy) NSString *questionid;
|
||||
|
||||
//试题标题
|
||||
@property (nonatomic, copy) NSString *question;
|
||||
|
||||
//题目类型(1单选题 2多选题 3判断题 4填空题 5简答题)
|
||||
@property (nonatomic, copy) NSString *questiontype;
|
||||
|
||||
//题目类型文本(单选题、多选题、判断题、填空题、简答题)
|
||||
@property (nonatomic, copy) NSString *questiontype_text;
|
||||
|
||||
//选项数量
|
||||
@property (nonatomic, copy) NSString *questionselectnumber;
|
||||
|
||||
//用户填写的答案
|
||||
@property (nonatomic, strong) NSMutableArray *userAnswer;
|
||||
|
||||
//答案选项
|
||||
@property (nonatomic, strong) NSMutableArray *tkselect;
|
||||
|
||||
//正确答案(单选题、多选题、判断题)
|
||||
@property (nonatomic, copy) NSString *trueanswer;
|
||||
|
||||
//答案分析
|
||||
@property (nonatomic, copy) NSString *questiondescribe;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,13 @@
|
||||
//
|
||||
// GiGaQuestionModel.m
|
||||
// GIGA
|
||||
//
|
||||
// Created by lianxiang on 2018/8/23.
|
||||
// Copyright © 2018年 com.giga.ios. All rights reserved.
|
||||
//
|
||||
|
||||
#import "GiGaQuestionModel.h"
|
||||
|
||||
@implementation GiGaQuestionModel
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,32 @@
|
||||
//
|
||||
// GIGAQuetionView.h
|
||||
// GIGA
|
||||
//
|
||||
// Created by lianxiang on 2018/8/23.
|
||||
// Copyright © 2018年 com.giga.ios. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
typedef NS_ENUM(NSInteger,GIGAQuetionViewStle)
|
||||
{
|
||||
GIGAQuetionViewStleSingleChoice = 0,//单选
|
||||
GIGAQuetionViewStleMutipleChoice ,//多选
|
||||
GIGAQuetionViewStyleTrueOrFalse,//判断
|
||||
|
||||
};
|
||||
|
||||
@interface GIGAQuetionView : UIView
|
||||
//样式
|
||||
@property (nonatomic,assign,readonly) GIGAQuetionViewStle style;
|
||||
//答案数组
|
||||
@property (nonatomic,strong,readonly) NSArray *answerArr;
|
||||
//选中答案
|
||||
@property (nonatomic, copy, readonly) NSString *selectAnswer;
|
||||
//选中答案角标
|
||||
@property (nonatomic, copy, readonly) NSString *qrnum;
|
||||
//刷新布局
|
||||
- (void)reloadViewWithFrame:(CGRect)frame style:(GIGAQuetionViewStle)style answerArray:(NSArray *)answerArray userAnswers:(NSArray *)userAnswers;
|
||||
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,197 @@
|
||||
//
|
||||
// GIGAQuetionView.m
|
||||
// GIGA
|
||||
//
|
||||
// Created by lianxiang on 2018/8/23.
|
||||
// Copyright © 2018年 com.giga.ios. All rights reserved.
|
||||
//
|
||||
|
||||
#import "GIGAQuetionView.h"
|
||||
#import "GiGaHelper.h"
|
||||
#import "Masonry.h"
|
||||
@interface GIGAQuetionView()
|
||||
|
||||
@property (nonatomic, weak) UIView *view;
|
||||
@property (nonatomic, assign, readwrite) GIGAQuetionViewStle style;
|
||||
@property (nonatomic, strong, readwrite) NSArray *answerArr;
|
||||
@property (nonatomic, copy, readwrite) NSString *selectAnswer;
|
||||
@property (nonatomic, copy, readwrite) NSString *qrnum;
|
||||
|
||||
@end
|
||||
|
||||
@implementation GIGAQuetionView
|
||||
|
||||
- (UIView *)view
|
||||
{
|
||||
if (!_view) {
|
||||
UIView *view = [[UIView alloc] init];
|
||||
//view.backgroundColor = [UIColor blueColor];
|
||||
[self addSubview:view];
|
||||
_view = view;
|
||||
}
|
||||
return _view;
|
||||
}
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
if (self = [super init]) {
|
||||
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)reloadViewWithFrame:(CGRect)frame style:(GIGAQuetionViewStle)style answerArray:(NSArray *)answerArray userAnswers:(NSArray *)userAnswers
|
||||
{
|
||||
self.style = style;
|
||||
self.answerArr = answerArray;
|
||||
if (_style == GIGAQuetionViewStyleTrueOrFalse) self.answerArr = @[@"正确", @"错误"];
|
||||
|
||||
_selectAnswer = @"";
|
||||
_qrnum = @"";
|
||||
|
||||
if (userAnswers.count > 0) {
|
||||
_selectAnswer = [userAnswers componentsJoinedByString:@"|"];
|
||||
for (int i = 0; i < userAnswers.count; i++) {
|
||||
if ([_qrnum isEqualToString:@""]) {
|
||||
_qrnum = [NSString stringWithFormat:@"%d", [userAnswers[i] characterAtIndex:0] - 65];
|
||||
}else {
|
||||
_qrnum = [_qrnum stringByAppendingString:[NSString stringWithFormat:@"|%d", [userAnswers[i] characterAtIndex:0] - 65]];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[self removeView];
|
||||
[self creatControlWithFrame:frame];
|
||||
}
|
||||
|
||||
- (void)creatControlWithFrame:(CGRect)frame
|
||||
{
|
||||
CGFloat btnH = 25;
|
||||
CGFloat padding = 10.f;
|
||||
CGFloat labelY = 0;
|
||||
UIFont *font = [UIFont systemFontOfSize:14.f];
|
||||
|
||||
for (int i = 0; i < _answerArr.count; i++) {
|
||||
//去回车、换行
|
||||
NSString *labelText = _answerArr[i];
|
||||
labelText = [labelText stringByReplacingOccurrencesOfString:@"\r" withString:@""];
|
||||
labelText = [labelText stringByReplacingOccurrencesOfString:@"\n" withString:@""];
|
||||
|
||||
//内容高度
|
||||
CGFloat labelH = [GiGaHelper sizeWithText:labelText font:font maxSize:CGSizeMake(KMainW - 50, MAXFLOAT)].height;
|
||||
|
||||
//选项标签
|
||||
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(btnH + 5, labelY + 4, KMainW - 50, labelH)];
|
||||
label.text = labelText;
|
||||
label.font = font;
|
||||
label.numberOfLines = 0;
|
||||
label.textColor = GIGAUIColorFromRGBA(0x616161);
|
||||
[self.view addSubview:label];
|
||||
|
||||
labelY += MAX(labelH, btnH) + padding;
|
||||
|
||||
//选项框
|
||||
UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, CGRectGetMinY(label.frame) - 4, btnH, btnH)];
|
||||
btn.tag = i + 100;
|
||||
btn.showsTouchWhenHighlighted = NO;
|
||||
[btn setImage:[UIImage imageNamed:@"exerc_answer_option_nor"] forState:UIControlStateNormal];
|
||||
[btn setImage:[UIImage imageNamed:@"exerc_answer_option_sel"] forState:UIControlStateSelected];
|
||||
[btn addTarget:self action:@selector(btnOnClick:) forControlEvents:UIControlEventTouchUpInside];
|
||||
[self.view addSubview:btn];
|
||||
|
||||
//标签点击区域
|
||||
UIButton *labelBtn = [[UIButton alloc] initWithFrame:label.frame];
|
||||
labelBtn.tag = i + 200;
|
||||
[labelBtn addTarget:self action:@selector(labelBtnOnClick:) forControlEvents:UIControlEventTouchUpInside];
|
||||
[self.view addSubview:labelBtn];
|
||||
|
||||
if ([_qrnum rangeOfString:[NSString stringWithFormat:@"%d", i]].location != NSNotFound) {
|
||||
btn.selected = YES;
|
||||
labelBtn.selected = YES;
|
||||
}
|
||||
}
|
||||
|
||||
self.view.frame = CGRectMake(10, 0, KMainW - 20, labelY - padding);
|
||||
frame.size.height = labelY - padding;
|
||||
self.frame = frame;
|
||||
|
||||
[self setNeedsUpdateConstraints];
|
||||
[self mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.mas_equalTo(self.superview.mas_top).offset(frame.origin.y + 10);
|
||||
make.left.mas_equalTo(self.superview.mas_left).offset(30);
|
||||
make.height.mas_equalTo(frame.size.height);
|
||||
make.width.mas_equalTo(frame.size.width - 30*2);
|
||||
}];
|
||||
|
||||
}
|
||||
|
||||
- (void)btnOnClick:(UIButton *)btn
|
||||
{
|
||||
[self selectOptionWithBtn:btn tag:100];
|
||||
|
||||
[self setBtnSelectedWithTag:100];
|
||||
}
|
||||
|
||||
- (void)labelBtnOnClick:(UIButton *)labelBtn
|
||||
{
|
||||
[self selectOptionWithBtn:labelBtn tag:200];
|
||||
|
||||
[self setBtnSelectedWithTag:200];
|
||||
}
|
||||
|
||||
- (void)selectOptionWithBtn:(UIButton *)btn tag:(int)tag
|
||||
{
|
||||
NSString *selStr = [NSString stringWithFormat:@"%c", (int)btn.tag - tag + 65];
|
||||
|
||||
if (_style == GIGAQuetionViewStyleTrueOrFalse || _style == GIGAQuetionViewStleSingleChoice) {
|
||||
_selectAnswer = selStr;
|
||||
_qrnum = [NSString stringWithFormat:@"%ld", btn.tag - tag];
|
||||
for (int i = 0; i < _answerArr.count; i++) {
|
||||
UIButton *btn = [self.view viewWithTag:i + tag];
|
||||
btn.selected = NO;
|
||||
}
|
||||
btn.selected = YES;
|
||||
|
||||
}else if (_style == GIGAQuetionViewStleMutipleChoice) {
|
||||
btn.selected = !btn.selected;
|
||||
_selectAnswer = @"";
|
||||
_qrnum = @"";
|
||||
for (int i = 0; i < _answerArr.count; i++) {
|
||||
UIButton *selBtn = [self.view viewWithTag:i + tag];
|
||||
if (selBtn.selected) {
|
||||
if ([_selectAnswer isEqualToString:@""]) {
|
||||
_selectAnswer = [NSString stringWithFormat:@"%c", i + 65];
|
||||
_qrnum = [NSString stringWithFormat:@"%d", i];
|
||||
}else {
|
||||
_selectAnswer = [_selectAnswer stringByAppendingString:[NSString stringWithFormat:@"|%@", [NSString stringWithFormat:@"%c", i + 65]]];
|
||||
_qrnum = [_qrnum stringByAppendingString:[NSString stringWithFormat:@"|%d", i]];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setBtnSelectedWithTag:(NSInteger)tag
|
||||
{
|
||||
NSInteger otTag = tag == 100 ? 200 : 100;
|
||||
|
||||
for (int i = 0; i < _answerArr.count; i++) {
|
||||
UIButton *btn = [self.view viewWithTag:i + tag];
|
||||
UIButton *otBtn = [self.view viewWithTag:i + otTag];
|
||||
otBtn.selected = btn.selected;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)removeView
|
||||
{
|
||||
[self.view removeFromSuperview];
|
||||
self.view = nil;
|
||||
}
|
||||
|
||||
- (void)setStyle:(GIGAQuetionViewStle)style
|
||||
{
|
||||
_style = style;
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user