@@ -17,6 +17,8 @@
@property ( nonatomic , strong ) UITableView * tableView ;
@property ( nonatomic , strong ) GIGaQuestionSlider * slider ;
@property ( nonatomic , strong ) NYSliderPopover * poSlider ;
@property ( nonatomic , strong ) UIButton * noBtn ;
@property ( nonatomic , strong ) UIButton * yesBtn ;
@end
@@ -30,11 +32,13 @@
}
- ( instancetype ) initQuestionView: ( CGRect ) frame style: ( MaskQuetionViewStyle ) style titles: ( NSArray * ) titles {
- ( instancetype ) initQuestionView: ( CGRect ) frame style: ( MaskQuetionViewStyle ) style titles: ( NSArray * ) titles current: ( ExercisesModel * ) currentModel {
self = [ super initWithFrame : frame ] ;
if ( self ) {
self . dataArr = titles ;
self . currentModel = currentModel ;
self . answerList = currentModel . answerList ;
self . style = style ;
[ self creatSubs : style titles : titles ] ;
}
@@ -81,6 +85,7 @@
[ slider addTarget : self action : @selector ( updateValue : ) forControlEvents : UIControlEventValueChanged ] ;
self . poSlider = slider ;
[ self addSubview : slider ] ;
//self.poSlider.value = self.currentModel.slidervalue;
self . poSlider . transform = CGAffineTransformMakeRotation ( - M_PI / 2 ) ;
}
@@ -94,6 +99,7 @@
GIGaQuestionSlider * slider = [ [ GIGaQuestionSlider alloc ] initWithFrame : CGRectMake ( 0 , self . frame . size . height , self . frame . size . height , 13 ) type : type ] ;
[ slider addTarget : self action : @selector ( updateValue : ) forControlEvents : UIControlEventValueChanged ] ;
self . slider = slider ;
[ self . slider setValue : self . currentModel . slidervalue ] ;
[ self addSubview : slider ] ;
self . slider . transform = CGAffineTransformMakeRotation ( - M_PI / 2 ) ;
}
@@ -116,39 +122,72 @@
- ( void ) creatYseNoView {
UIButton * yesBtn = [ UIButton buttonWithType : UIButtonTypeCustom ] ;
yesBtn . backgroundColor = GIGARGB ( 181 , 14 , 14 , 1 ) ;
yesBtn . frame = CGRectMake ( self . center . x - 120 / 2 , 40 , 120 , 34 ) ;
[ yesBtn addTarget : self action : @selector ( yesBtnAction ) forControlEvents : UIControlEventTouchUpInside ] ;
NSAttributedString * preTitle = [ [ NSAttributedString alloc ] initWithString : @" 是 " attributes : @{ NSFontAttributeName : [ UIFont fontWithName : GIGA_FONTBOLD size : 18 ] , NSForegroundColorAttributeName : [ UIColor whiteColor ] } ] ;
[ yesBtn setAttributedTitle : preTitle forState : UIControlStateNormal ] ;
[ yesBtn addTarget : self action : @selector ( yesBtnAction : ) forControlEvents : UIControlEventTouchUpInside ] ;
yesBtn . layer . borderWidth = 1 ;
yesBtn . layer . borderColor = GIGARGB ( 181 , 14 , 14 , 1 ) . CGColor ;
yesBtn . layer . masksToBounds = YES ;
yesBtn . layer . cornerRadius = 2 ;
self . yesBtn = yesBtn ;
[ self addSubview : yesBtn ] ;
UIButton * noBtn = [ UIButton buttonWithType : UIButtonTypeCustom ] ;
noBtn . backgroundColor = [ UIColor whiteColor ] ;
noBtn . frame = CGRectMake ( self . center . x - 120 / 2 , CGRectGetMaxY ( yesBtn . frame ) + 31 , 120 , 34 ) ;
[ noBtn addTarget : self action : @selector ( noBtnAction ) forControlEvents : UIControlEventTouchUpInside ] ;
NSAttributedString * noBtnTitle = [ [ NSAttributedString alloc ] initWithString : @" 否 " attributes : @{ NSFontAttributeName : [ UIFont fontWithName : GIGA_FONTBOLD size : 18 ] , NSForegroundColorAttributeName : GIGARGB ( 181 , 14 , 14 , 1 ) } ] ;
[ noBtn setAttributedTitle : noBtnTitle forState : UIControlStateNormal ] ;
[ noBtn addTarget : self action : @selector ( noBtnAction : ) forControlEvents : UIControlEventTouchUpInside ] ;
noBtn . layer . borderWidth = 1 ;
noBtn . layer . borderColor = GIGARGB ( 181 , 14 , 14 , 1 ) . CGColor ;
noBtn . layer . masksToBounds = YES ;
noBtn . layer . cornerRadius = 2 ;
self . noBtn = noBtn ;
[ self addSubview : noBtn ] ;
//slidervalue 题目 是(是 否)类型 对应答案下标
if ( self . currentModel . slidervalue = = 1 ) {
[ self selectNOBtnState : self . noBtn ] ;
} else {
[ self selctYesBtnState : self . yesBtn ] ;
}
}
# pragma mark 是
- ( void ) yesBtnAction {
- ( void ) yesBtnAction: ( UIButton * ) btn {
[ self selctYesBtnState : btn ] ;
if ( self . delegate & & [ self . delegate performSelector : @selector ( yesOrNoChoiceModelAt : ) ] ) {
[ self . delegate yesOrNoChoiceModelAt : 0 ] ;
}
}
# pragma mark 否
- ( void ) noBtnAction {
[ self . delegate yesOrNoChoiceModelAt : 1 ] ;
- ( void ) noBtnAction: ( UIButton * ) btn {
[ self selectNOBtnState : btn ] ;
if ( self . delegate & & [ self . delegate performSelector : @selector ( yesOrNoChoiceModelAt : ) ] ) {
[ self . delegate yesOrNoChoiceModelAt : 1 ] ;
}
}
//
- ( void ) selctYesBtnState: ( UIButton * ) btn {
NSAttributedString * preTitle = [ [ NSAttributedString alloc ] initWithString : @" 是 " attributes : @{ NSFontAttributeName : [ UIFont fontWithName : GIGA_FONTBOLD size : 18 ] , NSForegroundColorAttributeName : [ UIColor whiteColor ] } ] ;
[ btn setAttributedTitle : preTitle forState : UIControlStateNormal ] ;
btn . backgroundColor = GIGARGB ( 181 , 14 , 14 , 1 ) ;
NSAttributedString * noBtnTitle = [ [ NSAttributedString alloc ] initWithString : @" 否 " attributes : @{ NSFontAttributeName : [ UIFont fontWithName : GIGA_FONTBOLD size : 18 ] , NSForegroundColorAttributeName : GIGARGB ( 181 , 14 , 14 , 1 ) } ] ;
[ self . noBtn setAttributedTitle : noBtnTitle forState : UIControlStateNormal ] ;
self . noBtn . backgroundColor = [ UIColor whiteColor ] ;
}
- ( void ) selectNOBtnState: ( UIButton * ) btn {
NSAttributedString * preTitle = [ [ NSAttributedString alloc ] initWithString : @" 否 " attributes : @{ NSFontAttributeName : [ UIFont fontWithName : GIGA_FONTBOLD size : 18 ] , NSForegroundColorAttributeName : [ UIColor whiteColor ] } ] ;
[ btn setAttributedTitle : preTitle forState : UIControlStateNormal ] ;
btn . backgroundColor = GIGARGB ( 181 , 14 , 14 , 1 ) ;
NSAttributedString * yesTitle = [ [ NSAttributedString alloc ] initWithString : @" 是 " attributes : @{ NSFontAttributeName : [ UIFont fontWithName : GIGA_FONTBOLD size : 18 ] , NSForegroundColorAttributeName : GIGARGB ( 181 , 14 , 14 , 1 ) } ] ;
[ self . yesBtn setAttributedTitle : yesTitle forState : UIControlStateNormal ] ;
self . yesBtn . backgroundColor = [ UIColor whiteColor ] ;
}
- ( void ) updateValue: ( UISlider * ) slider {
@@ -163,24 +202,41 @@
if ( _answerList . count < = 2 ) {
return ;
}
NSInteger totalCount = _answerList . count ;
//设置权值 20 ~ 50
CGFloat sliderFormatValue = value * 30 + 20 ;
if ( self . poSlider ) {
[ self . poSlider showPopover ] ;
self . poSlider . popover . textLabel . text = [ NSString stringWithFormat : @" %.f " , sliderFormatValue ] ;
}
//从下到上 范围50 ~ 20
//每一份高度
int powSize = 30 / ( totalCount - 1 ) ;
//第几份
NSInteger index = ( sliderFormatValue - 20 ) / powSize ;
//设置权值 20 ~ 60
NSString * valueF = [ NSString stringWithFormat : @" %.2f " , value ] ;
CGFloat sliderFormatValue = [ valueF floatValue ] * 40.f + 20.f ;
if ( sliderFormatValue = = 20.f ) {
self . poSlider . popover . textLabel . text = @" 20- " ;
} else if ( sliderFormatValue = = 60.f ) {
self . poSlider . popover . textLabel . text = @" 60+ " ;
} else {
self . poSlider . popover . textLabel . text = [ NSString stringWithFormat : @" %.f " , sliderFormatValue ] ;
}
if ( self . delegate & & [ self . delegate performSelector : @selector ( sliderChangeValueShouldChoiceModelAt : ) ] ) {
[ self . delegate sliderChangeValueShouldChoiceModelAt : index ] ;
}
// 范围0 ~ 100
//每一份高度
CGFloat powSize = 100.f / ( totalCount - 1 ) ;
//当前值
CGFloat currentValue = value * 100.f ;
//答案游标 1开始
int count = currentValue / powSize ;
//答案数组下标
int index = 0 ;
index = ( int ) _answerList . count - 1 - count ;
if ( index < 0 ) {
index = 0 ;
}
if ( self . delegate & & [ self . delegate performSelector : @selector ( sliderChangeValueShouldChoiceModelAt : slider : ) ] ) {
[ self . delegate sliderChangeValueShouldChoiceModelAt : index slider : value ] ;
}
}