Skip to content

Commit

Permalink
风险测评
Browse files Browse the repository at this point in the history
  • Loading branch information
huanglins committed Jan 10, 2018
1 parent a870eb6 commit 52b3924
Show file tree
Hide file tree
Showing 8 changed files with 268 additions and 114 deletions.
10 changes: 5 additions & 5 deletions VHLRiskEvaluation.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -171,20 +171,20 @@
BF77E3F12005FEE40021BB72 /* Images */ = {
isa = PBXGroup;
children = (
BF77E3F22005FEE40021BB72 /* [email protected] */,
BF77E3F32005FEE40021BB72 /* [email protected] */,
BF77E3F42005FEE40021BB72 /* [email protected] */,
BF77E3F52005FEE40021BB72 /* risk_result_top_2@3x.png */,
BF77E3FF2005FEE40021BB72 /* risk_result_top_1@2x.png */,
BF77E3F62005FEE40021BB72 /* [email protected] */,
BF77E3F22005FEE40021BB72 /* [email protected] */,
BF77E3F52005FEE40021BB72 /* [email protected] */,
BF77E3FA2005FEE40021BB72 /* [email protected] */,
BF77E3FB2005FEE40021BB72 /* [email protected] */,
BF77E3F72005FEE40021BB72 /* [email protected] */,
BF77E3F82005FEE40021BB72 /* [email protected] */,
BF77E3F92005FEE40021BB72 /* [email protected] */,
BF77E3FA2005FEE40021BB72 /* [email protected] */,
BF77E3FB2005FEE40021BB72 /* [email protected] */,
BF77E3FC2005FEE40021BB72 /* [email protected] */,
BF77E3FD2005FEE40021BB72 /* [email protected] */,
BF77E3FE2005FEE40021BB72 /* [email protected] */,
BF77E3FF2005FEE40021BB72 /* [email protected] */,
);
path = Images;
sourceTree = "<group>";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,24 @@
//

#import <UIKit/UIKit.h>
#import "VHLRiskEvaluationModel.h"

@class VHLRiskEvaluationResultViewController;
@protocol VHLRiskEvaluationResultViewControllerDelegate<NSObject>

- (void)restartRiskEvaluation:(NSMutableArray<VHLRiskEvaluationModel *> *)questionArray vc:(VHLRiskEvaluationResultViewController *)riskResultVC;

@end

/**
风险评测结果页
*/
@interface VHLRiskEvaluationResultViewController : UIViewController

@property (nonatomic, strong) NSMutableArray<VHLRiskEvaluationModel *> *questionArray; // 问题数组
@property (nonatomic, weak) id<VHLRiskEvaluationResultViewControllerDelegate> delegate;

/** 当前风险测试得分*/
- (void)setScore:(int)score;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@

@interface VHLRiskEvaluationResultViewController ()

@property (nonatomic, assign) int score; // 风险评测得分

@property (nonatomic, strong) UIImageView *topImageView;
@property (nonatomic, strong) UILabel *scoreLabel;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *contentLabel;

@property (nonatomic, strong) UIButton *goRiskButton;
@property (nonatomic, strong) UIButton *finishRiskButton;

@end

Expand All @@ -23,23 +28,39 @@ @implementation VHLRiskEvaluationResultViewController
- (void)viewDidLoad {
[super viewDidLoad];

self.title = @"风险评测";
self.title = @"风险测评";
self.view.backgroundColor = [UIColor colorWithRed:0.98 green:0.98 blue:0.98 alpha:1.00];
self.edgesForExtendedLayout = UIRectEdgeNone;
//
self.topImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"risk_start_top_info"]];
[self.view addSubview:self.topImageView];
self.topImageView.centerX = self.view.centerX;
self.topImageView.top = 50;
// 得分
self.scoreLabel = [[UILabel alloc] init];
self.scoreLabel.font = [UIFont systemFontOfSize:20];
self.scoreLabel.textAlignment = NSTextAlignmentCenter;
self.scoreLabel.textColor = [UIColor colorWithRed:0.26 green:0.26 blue:0.26 alpha:1.00];
[self.view addSubview:self.scoreLabel];
self.scoreLabel.left = 0;
self.scoreLabel.top = self.topImageView.bottom + 30;
self.scoreLabel.width = self.view.width;

if (self.score > 0) {
self.scoreLabel.text = [NSString stringWithFormat:@"- %d分 -", self.score];
self.scoreLabel.height = 18;
} else {
self.scoreLabel.height = 0;
}
//
self.titleLabel = [[UILabel alloc] init];
self.titleLabel.font = [UIFont systemFontOfSize:17];
self.titleLabel.font = [UIFont systemFontOfSize:18];
self.titleLabel.textAlignment = NSTextAlignmentCenter;
self.titleLabel.textColor = [UIColor colorWithRed:0.26 green:0.26 blue:0.26 alpha:1.00];
self.titleLabel.text = @"温馨提示";
[self.view addSubview:self.titleLabel];
self.titleLabel.left = 0;
self.titleLabel.top = self.topImageView.bottom + 30;
self.titleLabel.top = self.scoreLabel.bottom + 20;
self.titleLabel.width = self.view.width;
self.titleLabel.height = 18;

Expand All @@ -53,23 +74,106 @@ - (void)viewDidLoad {
self.contentLabel.size = contentSize;
self.contentLabel.centerX = self.view.centerX;
self.contentLabel.top = self.titleLabel.bottom + 20;
// 按钮
self.finishRiskButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, self.view.width * 0.85, 48)];
[self.finishRiskButton setBackgroundColor:[UIColor whiteColor]];
[self.finishRiskButton setTitle:@"重新测评" forState:UIControlStateNormal];
[self.finishRiskButton setTitleColor:[UIColor colorWithRed:0.42 green:0.78 blue:0.93 alpha:1.00] forState:UIControlStateNormal];
[self.finishRiskButton setTitleColor:[UIColor colorWithRed:0.42 green:0.78 blue:0.93 alpha:0.5] forState:UIControlStateHighlighted];
[self.view addSubview:self.finishRiskButton];
self.finishRiskButton.layer.cornerRadius = 24;
self.finishRiskButton.layer.borderWidth = 1;
self.finishRiskButton.layer.borderColor = [UIColor colorWithRed:0.42 green:0.78 blue:0.93 alpha:1.00].CGColor;
self.finishRiskButton.layer.masksToBounds = YES;

self.goRiskButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, self.view.width * 0.85, 65)];
[self.goRiskButton setBackgroundImage:[UIImage imageNamed:@"risk_start_button_bg"] forState:UIControlStateNormal];
[self.goRiskButton setBackgroundImage:[UIImage imageNamed:@"risk_start_button_bg"] forState:UIControlStateHighlighted];
self.goRiskButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, self.view.width * 0.85, 48)];
[self.goRiskButton setBackgroundColor:[UIColor colorWithRed:0.42 green:0.78 blue:0.93 alpha:1.00]];
[self.goRiskButton setTitle:@"开始测评" forState:UIControlStateNormal];
[self.goRiskButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[self.goRiskButton setTitleColor:[UIColor colorWithWhite:1.0 alpha:0.5] forState:UIControlStateHighlighted];
[self.view addSubview:self.goRiskButton];
self.goRiskButton.centerX = self.view.centerX;
self.goRiskButton.top = self.contentLabel.bottom + 20;
self.goRiskButton.layer.cornerRadius = 24;
self.goRiskButton.layer.masksToBounds = YES;
// 添加事件
[self.finishRiskButton addTarget:self action:@selector(goRiskClick:) forControlEvents:UIControlEventTouchUpInside];
[self.goRiskButton addTarget:self action:@selector(goRiskClick:) forControlEvents:UIControlEventTouchUpInside];

[self.goRiskButton addTarget:self action:@selector(goRiskClick) forControlEvents:UIControlEventTouchUpInside];
//
[self changeViewValue];
}
/** */
- (void)goRiskClick:(UIButton *)button {
NSString *title = button.titleLabel.text;
if ([title isEqualToString:@"开始测评"] || [title isEqualToString:@"重新测评"]) {
if ([self.delegate respondsToSelector:@selector(restartRiskEvaluation:vc:)]) {
__weak typeof(self) weakSelf = self;
[self.delegate restartRiskEvaluation:self.questionArray vc:weakSelf];
} else {
[self.navigationController popViewControllerAnimated:YES];
}
} else {
[self.navigationController popViewControllerAnimated:YES];
}
}
// ------------------------------------------------------------
- (void)changeViewValue {
if (!self.topImageView || !self.titleLabel) {
return;
}
//
if (self.score > 0) {
self.finishRiskButton.hidden = NO;

self.finishRiskButton.size = CGSizeMake((self.view.width - 60) / 2, 48);
self.finishRiskButton.left = 15;
self.finishRiskButton.top = self.contentLabel.bottom + 24;

- (void)goRiskClick {

self.goRiskButton.size = CGSizeMake((self.view.width - 60) / 2, 48);
self.goRiskButton.right = self.view.right - 15;
self.goRiskButton.top = self.contentLabel.bottom + 24;

[self.goRiskButton setTitle:@"完成测评" forState:UIControlStateNormal];
} else {
self.finishRiskButton.hidden = YES;

self.goRiskButton.size = CGSizeMake(self.view.width * 0.85, 48);
self.goRiskButton.centerX = self.view.centerX;
self.goRiskButton.top = self.contentLabel.bottom + 24;
}
if (_score > 8 && _score <= 14) { // 保守型
self.topImageView.image = [UIImage imageNamed:@"risk_result_top_1"];
self.titleLabel.text = @"您属于保守型投资者";
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:self.titleLabel.text];
NSRange itemRange = [self.titleLabel.text rangeOfString:[NSString stringWithFormat:@"保守型"]];
[attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:0.51 green:0.85 blue:0.31 alpha:1.00] range:itemRange];
self.titleLabel.attributedText = attributedString;

self.contentLabel.text = @"您具有较低的风险承受能力,您对风险总是存在的道理有清楚的认识,您愿意在风险较小的情况下,进行一些能够获得相对稳定收益的投资。您不适合选择预期收益率奇高的P2P融资标的。";
} else if (_score > 15 && _score <= 27) { // 稳健性
self.topImageView.image = [UIImage imageNamed:@"risk_result_top_2"];
self.titleLabel.text = @"您属于稳健型投资者";
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:self.titleLabel.text];
NSRange itemRange = [self.titleLabel.text rangeOfString:[NSString stringWithFormat:@"稳健型"]];
[attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:0.31 green:0.65 blue:0.95 alpha:1.00] range:itemRange];
self.titleLabel.attributedText = attributedString;

self.contentLabel.text = @"您的风险承受能力一般,对风险与收益之间的正比关系有清楚认识。您愿意进行一些预期收益率略高的投资,并为此承担略高于市场平均水平的风险,您适合选择预期收益率适中且信誉良好。";
} else if (_score > 27) {
self.topImageView.image = [UIImage imageNamed:@"risk_result_top_3"];
self.titleLabel.text = @"您属于积极型投资者";
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:self.titleLabel.text];
NSRange itemRange = [self.titleLabel.text rangeOfString:[NSString stringWithFormat:@"积极型"]];
[attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:0.94 green:0.58 blue:0.22 alpha:1.00] range:itemRange];
self.titleLabel.attributedText = attributedString;

self.contentLabel.text = @"您具有较高的风险承受能力,对高风险对应高收益的道理有清楚的认识。对预期收益率较高的投资更感兴趣,并愿意为此承担较大的风险。";
}
}

/** 当前风险测试得分*/
- (void)setScore:(int)score {
_score = score;
[self changeViewValue];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
#import <UIKit/UIKit.h>
#import "VHLRiskEvaluationModel.h"

@class VHLRiskEvaluationViewController;
@protocol VHLRiskEvaluationViewControllerDelegate<NSObject>

// 答题完成点击
- (void)riskEvaluationFinish:(NSMutableArray<VHLRiskEvaluationModel *> *)questionArray;
- (void)riskEvaluationFinish:(NSMutableArray<VHLRiskEvaluationModel *> *)questionArray vc:(VHLRiskEvaluationViewController *)reVC;

@end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ - (void)viewDidLoad {
_topStepView = [[VHLRiskEvaluationTopStepView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 60)];
[self.view addSubview:_topStepView];

_contentScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 60, self.view.width, self.view.height - 60 - 20 - self.navigationController.navigationBar.height - [UIApplication sharedApplication].statusBarFrame.size.height)];
_contentScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 60, self.view.width, self.view.height - 60 - 40 - self.navigationController.navigationBar.height - [UIApplication sharedApplication].statusBarFrame.size.height)];
_contentScrollView.pagingEnabled = YES;
_contentScrollView.bounces = NO;
_contentScrollView.scrollEnabled = NO;
Expand All @@ -50,7 +50,7 @@ - (void)viewDidLoad {
}
self.contentScrollView.contentSize = CGSizeMake(self.view.width * self.questionArray.count, self.contentScrollView.height);
//
[self upQuestionClick:nil cIndex:0];
[self upQuestionClick:nil cIndex:-1];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
Expand All @@ -73,24 +73,24 @@ - (void)upQuestionClick:(VHLRiskEvaluationModel *)questionModel cIndex:(int)inde
VHLRiskEvaluationModel *rightQuestionModel = [self.questionArray lastObject];
NSString *leftStr = [NSString stringWithFormat:@"%ld", leftQuestionModel.index];
NSString *rightStr = [NSString stringWithFormat:@"%ld", rightQuestionModel.index];
[self.topStepView setLeftValue:leftStr rightValue:rightStr progress:((tempValue + 1) - 1) / (CGFloat)self.questionArray.count];
[self.topStepView setLeftValue:leftStr rightValue:rightStr progress:(tempValue + 1) / (CGFloat)self.questionArray.count pAnimation:(index < 0?NO:YES)];
//
[self.contentScrollView setContentOffset:CGPointMake(self.contentScrollView.width * tempValue, 0) animated:YES];
}
- (void)nextQuestionClick:(VHLRiskEvaluationModel *)questionModel cIndex:(int)index{
if (index >= self.questionArray.count - 1) {
// 点击完成
if ([self.delegate respondsToSelector:@selector(riskEvaluationFinish:)]) {
[self.navigationController popViewControllerAnimated:NO];
[self.delegate riskEvaluationFinish:self.questionArray];
if ([self.delegate respondsToSelector:@selector(riskEvaluationFinish:vc:)]) {
__weak typeof(self) weakSelf = self;
[self.delegate riskEvaluationFinish:self.questionArray vc:weakSelf];
}
return;
}
VHLRiskEvaluationModel *leftQuestionModel = self.questionArray[index + 1];
VHLRiskEvaluationModel *rightQuestionModel = [self.questionArray lastObject];
NSString *leftStr = [NSString stringWithFormat:@"%ld", leftQuestionModel.index];
NSString *rightStr = [NSString stringWithFormat:@"%ld", rightQuestionModel.index];
[self.topStepView setLeftValue:leftStr rightValue:rightStr progress:((index + 1) + 1) / (CGFloat)self.questionArray.count];
[self.topStepView setLeftValue:leftStr rightValue:rightStr progress:((index + 1) + 1) / (CGFloat)self.questionArray.count pAnimation:YES];
//
[self.contentScrollView setContentOffset:CGPointMake(self.contentScrollView.width * (index + 1), 0) animated: YES];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
@property (nonatomic, strong) UIProgressView *progressView;

//
- (void)setLeftValue:(NSString *)leftValue rightValue:(NSString *)rightValue progress:(CGFloat)progressValue;
- (void)setLeftValue:(NSString *)leftValue rightValue:(NSString *)rightValue progress:(CGFloat)progressValue pAnimation:(BOOL)isAnimation;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ - (instancetype)initWithFrame:(CGRect)frame {
return self;
}
//
- (void)setLeftValue:(NSString *)leftValue rightValue:(NSString *)rightValue progress:(CGFloat)progressValue {
- (void)setLeftValue:(NSString *)leftValue rightValue:(NSString *)rightValue progress:(CGFloat)progressValue pAnimation:(BOOL)isAnimation {
self.leftLabel.text = leftValue;
self.rightLabel.text = rightValue;
[self.progressView setProgress:progressValue animated:YES];
[self.progressView setProgress:progressValue animated:isAnimation];
}

@end
Loading

0 comments on commit 52b3924

Please sign in to comment.