ios中addtarget的用法

王朝学院·作者佚名  2016-08-27
窄屏简体版  字體: 小  |  中  |  大  |  超大  

1.addtarget 的。部分使用事件没有直接的操作方式,需要进行调用。就要用addTarget。

- (void)setupCustomView {

self.customView= [[CHViewalloc] init];

self.customView.translatesAutoresizingMaskIntoConstraints=NO;

[self.viewaddSubview:self.customView];

NSDictionary *viewsDictionary =@{@"topLayoutGuide":self.topLayoutGuide,

@"customView":self.customView

};

[self.viewaddConstraints:[NSLayoutConstraintconstraintsWithVisualFormat:@"V:|[topLayoutGuide][customView]|"

options:0

metrics:nil

views:viewsDictionary]];

[self.viewaddConstraints:[NSLayoutConstraintconstraintsWithVisualFormat:@"H:|[customView]|"

options:0

metrics:nil

views:viewsDictionary]];

[selfsetupSliders];

[selfupdateColors];

[selfsetupTargetActions];

}

- (void)setupSliders {

self.customView.trackWidthSlider.maximumValue=100.0;

self.customView.gaugeWidthSlider.maximumValue=100.0;

self.customView.valueSlider.value=self.customView.gauge.value;

self.customView.trackWidthSlider.value=self.customView.gauge.trackWidth;

self.customView.gaugeWidthSlider.value=self.customView.gauge.gaugeWidth;

self.customView.valueSliderLabel.text= [selfformattedStringForFloatValue:(self.customView.gauge.value*100)];

self.customView.trackWidthSliderLabel.text= [selfformattedStringForFloatValue:self.customView.gauge.trackWidth];

self.customView.gaugeWidthSliderLabel.text= [selfformattedStringForFloatValue:self.customView.gauge.gaugeWidth];

self.customView.valueSlider.continuous=NO;

self.customView.trackWidthSlider.continuous=NO;

self.customView.gaugeWidthSlider.continuous=NO;

}

- (void)updateColors {

self.customView.valueColorIndicatorView.backgroundColor=self.customView.gauge.textColor;

self.customView.trackColorIndicatorView.backgroundColor=self.customView.gauge.trackTintColor;

self.customView.gaugeColorIndicatorView.backgroundColor=self.customView.gauge.gaugeTintColor;

}

- (void)setupTargetActions {

UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(changeState:)];

[self.customView.gaugeaddGestureRecognizer:tapGestureRecognizer];

[self.customView.gaugeStyleSwitchaddTarget:selfaction:@selector(changeGuageStyle:) forControlEvents:UIControlEventValueChanged];

[self.customView.valueSlideraddTarget:selfaction:@selector(valueSliderChangedValue:) forControlEvents:UIControlEventValueChanged];

[self.customView.trackWidthSlideraddTarget:selfaction:@selector(trackWidthSliderChangedValue:) forControlEvents:UIControlEventValueChanged];

[self.customView.gaugeWidthSlideraddTarget:selfaction:@selector(gaugeWidthSliderChangedValue:) forControlEvents:UIControlEventValueChanged];

tapGestureRecognizer = [[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(changeValueColor:)];

[self.customView.valueColorIndicatorViewaddGestureRecognizer:tapGestureRecognizer];

tapGestureRecognizer = [[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(changeTrackColor:)];

[self.customView.trackColorIndicatorViewaddGestureRecognizer:tapGestureRecognizer];

tapGestureRecognizer = [[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(changeGaugeColor:)];

[self.customView.gaugeColorIndicatorViewaddGestureRecognizer:tapGestureRecognizer];

}

#PRagma mark - Action Methods

- (void)changeState:(UITapGestureRecognizer *)tapGestureRecognizer {

if(self.customView.gauge.state!= CHCircleGaugeViewStateNA) {

self.customView.gauge.state= CHCircleGaugeViewStateNA;

}else {

[self.customView.gaugesetValue:self.customView.gauge.valueanimated:YES];

}

}

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航