• ios中addtarget的用法


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

    - (void)setupCustomView {

        

        self.customView = [[CHView alloc] init];

        self.customView.translatesAutoresizingMaskIntoConstraints = NO;

        

        [self.view addSubview:self.customView];

        

        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.valueSliderLabel.text = [self formattedStringForFloatValue:(self.customView.gauge.value * 100)];

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

        self.customView.gaugeWidthSliderLabel.text = [self formattedStringForFloatValue: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 = [[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 (self.customView.gauge.state != CHCircleGaugeViewStateNA) {

            self.customView.gauge.state = CHCircleGaugeViewStateNA;

        } else {

            [self.customView.gauge setValue:self.customView.gauge.value animated:YES];

        }

    }

  • 相关阅读:
    关于下拉框在页面加载时候选中值得问题
    《锋利的jQuery》要点归纳(二) jQuery中的DOM操作(上)
    《锋利的jQuery》要点归纳(三) jQuery中的事件和动画(下:动画篇)
    《锋利的jQuery》要点归纳(四)jQuery对表单、表格的操作及更多应用(上:表单应用)
    getElementById函数的一些发现
    《锋利的jQuery》要点归纳(三) jQuery中的事件和动画(上:事件篇)
    《锋利的jQuery》要点归纳(四)jQuery对表单、表格的操作及更多应用(中:表格应用)
    BENNY妙笔生花博皮博客园即将发布
    《锋利的jQuery》要点归纳(二) jQuery中的DOM操作(下)
    《锋利的jQuery》要点归纳(一) jQuery选择器
  • 原文地址:https://www.cnblogs.com/wcLT/p/4119315.html
Copyright © 2020-2023  润新知