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];

}

}

ios中addtarget的用法的更多相关文章

  1. iOS中block的用法 以及和函数用法的区别

    ios中block的用法和函数的用法大致相同 但是block的用法的灵活性更高: 不带参数的block: void ^(MyBlock)() = ^{}; 调用的时候  MyBlock(); 带参数的 ...

  2. ios中addtarget

    Target-action:目标-动作模式,它贯穿于iOS开发始终.但是对于初学者来说,还是被这种模式搞得一头雾水. 其实Target-action模式很简单,就是当某个事件发生时,调用那个对象中的那 ...

  3. iOS中Block的用法,举例,解析与底层原理(这可能是最详细的Block解析)

    1. 前言 Block:带有自动变量(局部变量)的匿名函数.它是C语言的扩充功能.之所以是拓展,是因为C语言不允许存在这样匿名函数. 1.1 匿名函数 匿名函数是指不带函数名称函数.C语言中,函数是怎 ...

  4. ios中图片拉伸用法

    - (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCap ...

  5. iOS中的CocoaPods用法及常用命令

     CocoaPods是什么? ***CocoaPods的使用场景:*** 1. 当你开发iOS应用时,会经常使用到很多第三方开源类库,比如JSONKit,AFNetWorking等等.可能某个类库又用 ...

  6. ios中Pldatabase的用法

    将PLDATABASE加入到工程 下载PLDatabase 的dmg文件 将PLDatabase的framework复制到工程根目录在工程中加入该framework使用该framework进行数据库操 ...

  7. iOS中NSScanner 的用法

    NSScanner是一个类,用于在字符串中扫描指定的字符,尤其是把它们翻译/转换为数字和别的字符串.可以创建NSScanner时制定他的String属性,然后scanner会按照你的要求从头到尾扫描这 ...

  8. IOS中NSUserDefaults的用法(轻量级本地数据存储)

    NSUserDefaults适合存储轻量级的本地数据,比如要保存一个登陆界面的数据,用户名.密码之类的,个人觉得使用NSUserDefaults是首选.下次再登陆的时候就可以直接从NSUserDefa ...

  9. IOS中TableView的用法

    一.UITableView 1.数据展示的条件 1> UITableView的所有数据都是由数据源(dataSource)提供的,所以要想在UITableView展示数据,必须设置UITable ...

随机推荐

  1. wap_supplicant介绍

    目前可以使用wireless-tools 或wpa_supplicant工具来配置无线网络.请记住重要的一点是,对无线网络的配置是全局性的,而非针对具体的接口. wpa_supplicant是一个较好 ...

  2. posix thread 浅谈

    用Posix thread进行多线程设计,就不怕跨平台了,因为很多OS都兼容Posix thread,如Linux/Windows等,甚至嵌入式系统上(如rt-thread)都支持posix thre ...

  3. 简单好用的 AJAX 上传插件,还可以抛弃难看的 file 按钮哦~

    在做网页设计的时候,设计师常常会把上传按钮设计得非常漂亮,还用了什么放大镜之类的图标来表达 browse 的效果.可是她们不知道,type="file" 的按钮在不同浏览器上的效果 ...

  4. mysql数据恢复

    [1] 当数据库被删除后的恢复方法   首先建立一个测试用的数据库.  mysql -u root -p123123   ← 用root登录到MySQL服务器  Enter password:  ←  ...

  5. 常用的Eclilpse插件列表以及安装方式总结

    Eclipse常用插件的安装方式总结: 1.Maven Integration for Eclipse WTP     作用:用来方便开发和使用maven项目.     安装方式:Eclipse Ma ...

  6. 【BZOJ】【1833】【ZJOI2010】count 数字计数

    数位DP Orz iwtwiioi 学习了一下用记忆化搜索来捉题的新姿势……但没学会TAT,再挖个坑(妈蛋难道对我来说数位DP就是个神坑吗……sigh) //BZOJ 1833 #include< ...

  7. 2013 Asia Regional Changchun

    Hard Code http://acm.hdu.edu.cn/showproblem.php?pid=4813 #include<cstdio> ]; int main(){ int t ...

  8. PrintQueue

    PrintQueueCollection printQueues = null; var printServer = new PrintServer(); printQueues = printSer ...

  9. uva 10160

    一开始写的代码加上各种剪枝后还是超时, 然后看了一下状态压缩后过了,两个代码的具体思想是一样的,状态压缩后可以大大提升性能 #include <cstdio> #include <c ...

  10. Unity3D 游戏开发构架篇 ——角色类的设计与持久化

    在游戏开发中,游戏角色占了很大的篇幅,可以说游戏中所有的内容都是由主角所带动.这里就介绍一下角色类的设计和持久化. 一.角色类应用场景和设计思想 游戏中的角色类型不一而足,有不同的技能,有不同的属性等 ...