此文学习来源为:http://study.163.com/course/introduction/1002858003.htm

此工程文件实现功能:

 1、定义UIStepperUISegmentedControl对象和属性

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:步进器和分栏控件的更多相关文章

  1. IOS开发之XCode学习014:警告对话框和等待提示器

    此文学习来源为:http://study.163.com/course/introduction/1002858003.htm 此工程文件实现功能:  1.警告对话框和等待提示器的概念 2.警告对话框 ...

  2. IOS开发之XCode学习011:UISwitch控件

    此文学习来源为:http://study.163.com/course/introduction/1002858003.htm 此工程文件实现功能:  1.定义UIswitch控件,添加UIswitc ...

  3. IOS开发之XCode学习009:UIViewController使用

    此文学习来源为:http://study.163.com/course/introduction/1002858003.htm 此工程文件实现功能: 通过点击屏幕事件,调用ViewController ...

  4. IOS开发之XCode学习008:UIViewController基础

    此文学习来源为:http://study.163.com/course/introduction/1002858003.htm 红色框选部分用A代替,AppDelegate类在程序框架启动时,如果在i ...

  5. IOS开发之XCode学习007:UIWindow对象

    此文学习来源为:http://study.163.com/course/introduction/1002858003.htm #import "AppDelegate.h" @i ...

  6. IOS开发之XCode学习012:Slider和ProgressView

    此文学习来源为:http://study.163.com/course/introduction/1002858003.htm 此工程文件实现功能:  1.定义UISlider和UIProgressV ...

  7. IOS开发之XCode学习010:定时器和视图对象

    此文学习来源为:http://study.163.com/course/introduction/1002858003.htm 此工程文件实现功能: 1.通过点击"启动定时器"按钮 ...

  8. iOS开发之Xcode常用调试技巧总结

    转载自:iOS开发之Xcode常用调试技巧总结 最近在面试,面试过程中问到了一些Xcode常用的调试技巧问题.平常开发过程中用的还挺顺手的,但你要突然让我说,确实一脸懵逼.Debug的技巧很多,比如最 ...

  9. iOS开发之Xcode 如何使用API帮助

    内容转载自<iOS开发指南 2.6.2 如何使用API帮助> 对于一个初学者来说,学会在Xcode中使用API帮助文档是非常重要的.下面我们通过一个例子来介绍API帮助文档的用法.在编写H ...

随机推荐

  1. POJ 3304 Segments[直线与线段相交]

    Segments Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13514   Accepted: 4331 Descrip ...

  2. 【视频编解码·学习笔记】6. H.264码流分析工程创建

    一.准备工作: 新建一个VS工程SimpleH264Analyzer, 修改工程属性参数-> 输出目录:$(SolutionDir)bin\$(Configuration)\,工作目录:$(So ...

  3. Java的一些良好习惯及细节------持续更新中...

    1.在做条件判断时,不要将变量放在判断符的左边,这样做可以防止出现空指针异常,以字符串比较为例: String name = "Tom"; //这种方式不推荐,如果变量name为空 ...

  4. pandas读取各类sql数据源

    大数据分析中,我们经常需要使用pandas工具读取各类数据源并将结果保存到数据库中. 本文总结了一些读取和写入常用数据库数据的一些方法,包括mysql,oracle,impala等. 其中读取数据库数 ...

  5. javascript 数字字母组合的随机数

    Math.random()方法用于生成,结果为0-1间的一个伪随机数(包括0,不包括1) ,通常的办法是结合parseInt().Math.floor() 或者 Math.ceil()进行四舍五入处理 ...

  6. php扩展开发实战教程(1)

    我的开发环境: Ubuntu16.04 apt方式安装的php5.6, apache,mysql等 由于我的本机用的是apt方式安装的php,所以我这里从头开始用最精简的方式,编译安装一个php5.4 ...

  7. 使用Dism备份和全新恢复系统

    1.使用WinPE启动,winPE制作可以参考我的另一文章http://www.cnblogs.com/karl-F/p/6934086.html 2.捕获C盘镜像 (1)查看磁盘 在PE提示符:输入 ...

  8. Install Centrifugo and quick start

    Install Centrifugo and quick start Go is a perfect language - it gives developers an opportunity to ...

  9. angularjs MVC、模块化、依赖注入详解

    一.MVC <!doctype html> <html ng-app> <head> <meta charset="utf-8"> ...

  10. 940C Phone Numbers

    传送门 题目大意 给你两个数字n和k,给你一个字符串s,n是s的长度,求字母集合是s的字母集合子集的字典序大于s的长度为k的字典序最小的字符串t 分析 将字符转化为数字,然后分两种情况处理: 1.n& ...