1.addtarget. Some use events do not have a direct operation and need to be called. We'll use Addtarget.
-(void) Setupcustomview {
self. CustomView = [[chview alloc] init];
self. CustomView. translatesautoresizingmaskintoconstraints = NO;
[self. View addsubview:selfcustomview];
nsdictionary *viewsdictionary = @{ @ "toplayoutguide": Self . Toplayoutguide,
@ "CustomView": Self . CustomView
};
[self. View addconstraints: [nslayoutconstraint constraintswithvisualformat:@ "v:|[ toplayoutguide][customview]| "
options:0
metrics:Nil
Views:viewsdictionary]];
[self. View addconstraints: [nslayoutconstraint constraintswithvisualformat:@ "h:|[ customview]| "
options:0
metrics:Nil
Views:viewsdictionary]];
[self setupsliders];
[self updatecolors];
[self setuptargetactions];
}
-(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.text = [self Formattedstringforfloatvalue:(self.customview .gauge.value * 100
self. CustomView. Trackwidthsliderlabel. Text = [self formattedstringforfloatvalue: Self . CustomView. Gaugetrackwidth];
self. CustomView. Gaugewidthsliderlabel. Text = [ self Formattedstringforfloatvalue:selfcustomview. 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 = [[uitapgesturerecognizer alloc] initwithtarget: Self action:@selector (changestate:)];
[self. CustomView. Gauge addgesturerecognizer: Tapgesturerecognizer];
[self. CustomView. Gaugestyleswitch addTarget:self Action:@selector (Changeguagestyle:) forcontrolevents: uicontroleventvaluechanged];
[self. CustomView. Valueslider addTarget:self Action:@selector( Valuesliderchangedvalue:) forcontrolevents: uicontroleventvaluechanged];
[self. CustomView. Trackwidthslider addTarget:self Action:@selector (trackwidthsliderchangedvalue:) forcontrolevents: uicontroleventvaluechanged];
[self. CustomView. Gaugewidthslider addTarget:self Action:@selector( Gaugewidthsliderchangedvalue:) forcontrolevents: uicontroleventvaluechanged];
Tapgesturerecognizer = [[uitapgesturerecognizer alloc] initwithtarget:self action:@ Selector (changevaluecolor:)];
[self. CustomView. Valuecolorindicatorview addgesturerecognizer: Tapgesturerecognizer];
Tapgesturerecognizer = [[uitapgesturerecognizer alloc] initwithtarget:self action:@ Selector (changetrackcolor:)];
[self. CustomView. Trackcolorindicatorview addgesturerecognizer: Tapgesturerecognizer];
Tapgesturerecognizer = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector (Changegaugecolor:)];
[self. CustomView. Gaugecolorindicatorview addgesturerecognizer: Tapgesturerecognizer];
}
#pragma mark-action Methods
-(void) Changestate: (UITapGestureRecognizer *) Tapgesturerecognizer {
if (customview.gauge. State! = Chcirclegaugeviewstatena) {
self. CustomView. Gauge state = Chcirclegaugeviewstatena;
} Else {
[self. CustomView. Gauge setValue:self. CustomView. Gauge. Value Animated :YES];
}
}
Usage of addtarget in iOS