Usage of addtarget in iOS

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.