IOS开发之XCode学习013:步进器和分栏控件
此文学习来源为:http://study.163.com/course/introduction/1002858003.htm
此工程文件实现功能:
1、定义UIStepper和UISegmentedControl对象和属性
2、设置UIStepper和UISegmentedControl的基本属性,如最小值
3、添加事件函数
===========================ViewController.h脚本==============================
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
{
//定义步进器对象
//按照一定的数值来调整某个数据
UIStepper* _stepper;
//定义分栏控件对象
UISegmentedControl* _segControl;
}
//属性的定义
@property (retain,nonatomic) UIStepper* stepper;
@property (retain,nonatomic) UISegmentedControl* segControl;
@end
===========================ViewController.m脚本==============================
@synthesize stepper = _stepper;
@synthesize segControl = _segControl;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//创建步进器对象
_stepper = [[UIStepper alloc] init];
//设置位置,宽高不能变更
_stepper.frame = CGRectMake(100, 100, 80, 40);
//设置步进器的最小值
_stepper.minimumValue = 0;
//设置步进器的最大值
_stepper.maximumValue = 100;
//设置步进器的当前值,默认值为0
_stepper.value = 10;
//设置步进值,每次向前或向后步进的步伐值
_stepper.stepValue = 10;
//是否可以重复响应事件操作,YES:按住“+”或“-”号可以重复执行 NO:按住一次松开,才执行,按住不重复操作
_stepper.autorepeat = YES;
//是否将步进结果通过事件函数响应出来
//YES:会把数据的变化过程显示出来,如从100到50,会依次显示100、90、80、70、60、50
//NO:只显示变化的初始值和默认值,如从100到50,只显示100、50
_stepper.continuous = YES;
//添加事件函数
//1:函数实现体
//2:函数体
//3:事件值改变的状态
[_stepper addTarget:self action:@selector(stepChange) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:_stepper];
//创建分栏控件
_segControl = [[UISegmentedControl alloc] init];
//设置控件位置,宽度可变,高度不可变
_segControl.frame = CGRectMake(10, 200, 300, 40);
//添加一个按钮元素
//P1:按钮选项文字
//P2:按钮的索引位置
//P3:是否有插入的动画效果
[_segControl insertSegmentWithTitle:@"0元" atIndex:0 animated:NO];
[_segControl insertSegmentWithTitle:@"5元" atIndex:1 animated:NO];
[_segControl insertSegmentWithTitle:@"10元" atIndex:2 animated:NO];
//当前默认按钮索引设置
_segControl.selectedSegmentIndex = 0;
[_segControl addTarget:self action:@selector(segChange) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:_segControl];
}
-(void)segChange
{
NSLog(@"%d",_segControl.selectedSegmentIndex);
}
-(void)stepChange
{
NSLog(@"step progress,当前值为:%f",_stepper.value);
}
运行结果:
学习总结:
- 重点:步进器和分栏控件的属性
- 难点:步进器和分栏控件的使用
源码链接地址:https://pan.baidu.com/s/1yrOLXZZeu9MiOWtMq5-EGA 密码:7t1l
IOS开发之XCode学习013:步进器和分栏控件的更多相关文章
- IOS开发之XCode学习014:警告对话框和等待提示器
此文学习来源为:http://study.163.com/course/introduction/1002858003.htm 此工程文件实现功能: 1.警告对话框和等待提示器的概念 2.警告对话框 ...
- IOS开发之XCode学习011:UISwitch控件
此文学习来源为:http://study.163.com/course/introduction/1002858003.htm 此工程文件实现功能: 1.定义UIswitch控件,添加UIswitc ...
- IOS开发之XCode学习009:UIViewController使用
此文学习来源为:http://study.163.com/course/introduction/1002858003.htm 此工程文件实现功能: 通过点击屏幕事件,调用ViewController ...
- IOS开发之XCode学习008:UIViewController基础
此文学习来源为:http://study.163.com/course/introduction/1002858003.htm 红色框选部分用A代替,AppDelegate类在程序框架启动时,如果在i ...
- IOS开发之XCode学习007:UIWindow对象
此文学习来源为:http://study.163.com/course/introduction/1002858003.htm #import "AppDelegate.h" @i ...
- IOS开发之XCode学习012:Slider和ProgressView
此文学习来源为:http://study.163.com/course/introduction/1002858003.htm 此工程文件实现功能: 1.定义UISlider和UIProgressV ...
- IOS开发之XCode学习010:定时器和视图对象
此文学习来源为:http://study.163.com/course/introduction/1002858003.htm 此工程文件实现功能: 1.通过点击"启动定时器"按钮 ...
- iOS开发之Xcode常用调试技巧总结
转载自:iOS开发之Xcode常用调试技巧总结 最近在面试,面试过程中问到了一些Xcode常用的调试技巧问题.平常开发过程中用的还挺顺手的,但你要突然让我说,确实一脸懵逼.Debug的技巧很多,比如最 ...
- iOS开发之Xcode 如何使用API帮助
内容转载自<iOS开发指南 2.6.2 如何使用API帮助> 对于一个初学者来说,学会在Xcode中使用API帮助文档是非常重要的.下面我们通过一个例子来介绍API帮助文档的用法.在编写H ...
随机推荐
- I/O多路转接模型
body, table{font-family: 微软雅黑; font-size: 13.5pt} table{border-collapse: collapse; border: solid gra ...
- 闭包和es6实现循环绑定li输出固定索引值
首先我们需要一个html结构 <div > <ul> <li>a</li> <li>a</li> <li>a< ...
- springIOC、AOP的一些注解
springIOC.AOP的一些注解(使用这些注解之前要导入spring框架的一些依赖): 1.注入IOC容器 @Compontent:使用注解的方式添加到ioc容器需要在配置文件 ...
- 机器学习实践之Logistic回归
关于本文说明,本人原博客地址位于http://blog.csdn.net/qq_37608890,本文来自笔者于2017年12月17日 19:18:31所撰写内容(http://blog.cs ...
- ChineseUtils
这里获得汉字的拼音使用了pinyin4j这个插件,因为多音字的原因效果并不理想 /** * 获得汉字拼音 * @param name * @return */ @SuppressWarnings(&q ...
- WPF ----在UserControl的xaml里绑定依赖属性
场景:在定义wpf 用户控件的时候,希望使用时设置自定义的属性来改变用户控件里的状态或内容等. 下面直接上实例代码: 用户控件的后台代码,定义依赖属性 public partial class MyU ...
- Chrome浏览器的自动安装下载工具
链接 https://www.google.com/chrome/browser/desktop/index.html?brand=CHWL&utm_campaign=en&utm_s ...
- [原创]Oracle 12c的备份和恢复策略
Oracle 12c的备份和恢复策略(RMAN备份[开启归档/控制文件/数据文件/归档日志]): 备份策略: * 每半年做一个数据库的全备份(包括所有的数据和只读表空间) * 每周做一次零级备份 * ...
- C#委托与事件--简单笔记
委托 简单记录点东西 适合似懂非懂的朋友看看 委托类型用来定义和响应应用程序中的回调. 借此可以设计各种有面向对象特性的代码模式.下面要说的事件在我看来就是委托的一种实现,再深一步讲,利用委托加事件, ...
- ubuntu17.10 python3.6 install plugins for AI
install order: tensorflow-gpu scikit-learn numpy scipy matplotlib tkinter tensorflow-gpu : pip insta ...