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];
}
}
ios中addtarget的用法的更多相关文章
- iOS中block的用法 以及和函数用法的区别
ios中block的用法和函数的用法大致相同 但是block的用法的灵活性更高: 不带参数的block: void ^(MyBlock)() = ^{}; 调用的时候 MyBlock(); 带参数的 ...
- ios中addtarget
Target-action:目标-动作模式,它贯穿于iOS开发始终.但是对于初学者来说,还是被这种模式搞得一头雾水. 其实Target-action模式很简单,就是当某个事件发生时,调用那个对象中的那 ...
- iOS中Block的用法,举例,解析与底层原理(这可能是最详细的Block解析)
1. 前言 Block:带有自动变量(局部变量)的匿名函数.它是C语言的扩充功能.之所以是拓展,是因为C语言不允许存在这样匿名函数. 1.1 匿名函数 匿名函数是指不带函数名称函数.C语言中,函数是怎 ...
- ios中图片拉伸用法
- (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCap ...
- iOS中的CocoaPods用法及常用命令
CocoaPods是什么? ***CocoaPods的使用场景:*** 1. 当你开发iOS应用时,会经常使用到很多第三方开源类库,比如JSONKit,AFNetWorking等等.可能某个类库又用 ...
- ios中Pldatabase的用法
将PLDATABASE加入到工程 下载PLDatabase 的dmg文件 将PLDatabase的framework复制到工程根目录在工程中加入该framework使用该framework进行数据库操 ...
- iOS中NSScanner 的用法
NSScanner是一个类,用于在字符串中扫描指定的字符,尤其是把它们翻译/转换为数字和别的字符串.可以创建NSScanner时制定他的String属性,然后scanner会按照你的要求从头到尾扫描这 ...
- IOS中NSUserDefaults的用法(轻量级本地数据存储)
NSUserDefaults适合存储轻量级的本地数据,比如要保存一个登陆界面的数据,用户名.密码之类的,个人觉得使用NSUserDefaults是首选.下次再登陆的时候就可以直接从NSUserDefa ...
- IOS中TableView的用法
一.UITableView 1.数据展示的条件 1> UITableView的所有数据都是由数据源(dataSource)提供的,所以要想在UITableView展示数据,必须设置UITable ...
随机推荐
- Msys+Mingw在手 妙用在心!
1 缘起 平时在一些c++群面,看见很多大学十分努力的学习c++/MFC ,看见在编程语言百花争芳的时候,C/C++还是很有很有魅力.估计很多初学者使用都是window下的visual stdio 开 ...
- 从零开始学ios开发(九):Swapping Views
这篇的内容是切换Views,也是上一篇中提到的第三种当iphone发生旋转后改变布局的方式,先回顾一下上一篇中提到的三种方式 1.使用Autosizing 2.写code 3.重新弄个View,替换原 ...
- Swift和OC,是编译型语言、解释性语言、运行时语言
首先需要明确的一点是,什么是编译型语言和解释性语言 编译型语言,就是在其执行过程中需要先将其经过编译成机器码来给计算机识别的,其执行效率就会比较高这个是显而易见的,常见比如:C.C++ 而解释型语言, ...
- 3157: 国王奇遇记 & 3516: 国王奇遇记加强版 - BZOJ
果然我数学不行啊,题解君: http://www.cnblogs.com/zhuohan123/p/3726933.html const h=; var fac,facinv,powm,s:..]of ...
- Ext学习-基础组件介绍
1.目标 学习对象获取,组件基础,事件模型以及学习ExtJS中的基础组件的应用. 2.内容 1.对象获取 2.组件原理以及基础 3.事件模型 4.常用组件的介绍 3.学习步骤 1 ...
- C# 数据结构--排序[上]
概述 看了几天的排序内容,现在和大家分享一些常见的排序方法. 啥是排序? 个人理解的排序:通过对数组中的值进行对比,交换位置最终得到一个有序的数组.排序分为内存排序和外部排序.本次分享排序方法都为内存 ...
- SpringMVC数据绑定全面示例(复杂对象,数组等)
点击链接查询原文 http://www.xdemo.org/springmvc-data-bind/ 已经使用SpringMVC开发了几个项目,平时也有不少朋友问我数据怎么传输,怎么绑定之类的话题,今 ...
- android 解析XML方式(二)
上一节中,我们使用DOM方式解析xml文档,该方式比较符合我们日常思维方式,容易上手,但是它直接把文档调入内存中,比较耗内存.在这里我们可以用另外一种方式解析xml,这个就是SAX方式. SAX即是: ...
- Web Server 和 HTTP协议(转)
转自:http://www.kuqin.com/shuoit/20150809/347488.html 一直在找实习,有点什么东西直接就在evernote里面记了,也没时间来更新到这里.找实习真是个蛋 ...
- 空格的URL编码
Q: 为什么我看的教材一会说是“+” 一会说是“%20” A: urlencode(" ") '返回+encodeURI(" ") '返回%20是有区别的