一、UISlider

UIslider滑块控件在IOS开发中会常用到,可用于调节音量,字体大小等UI方面的交互;UISlider实例提供一个控件,让用户通过左右拖动一个滑块(可称其为“缩略图”)来选择一个值。默认情况下,滑块的最小值为0.0,最大值为1.0。当然可以在属性面板中通过设置minimumValue和maximumValue来进行定制这两个值。如果要为控件两端设置样式,可以添加一对相关图像(minimumValueImage和maximumValueImage属性)来加强该设置,也可在代码中通过setMimimumTrackImage: forState: 和setMaximumTrackImage: forState: 方法来添加设置两端图片。

UISwitch对象提供一个简单的开/关切换,允许用户选择一个布尔值。

常见属性:

1、value:

这个值是介于滑块的最大值和最小值之间的,如果没有设置边界值,默认为0-1;

2、minimumValue:

设置滑块最小边界值(默认为0)

3、maximumValue:

设置滑块最大边界值(默认为1)

4、minimumValueImage:

设置滑块最左端显示的图片

5、maximumValueImage

设置滑块最右端显示的图片

6、continuous(BOOL)

设置滑块值是否连续变化(默认为YES)

7、minimumTrackTintColor

设置滑块左边(小于部分)线条的颜色

8、maximumTrackTintColor:

设置滑块右边(大于部分)线条的颜色

9、thumbTintColor

设置滑块颜色(影响已划过一端的颜色),注意这个属性:如果你没有设置滑块的图片,那个这个属性将只会改变已划过一段线条的颜色,不会改变滑块的颜色,如果你设置了滑块的图片,又设置了这个属性,那么滑块的图片将不显示,滑块的颜色会改变。

常用方法:

手动设置滑块的值:

- (void)setValue:(float)value animated:(BOOL)animated;

设置滑块的图片:

- (void)setThumbImage:(UIImage *)image forState:(UIControlState)state;

设置滑块划过部分的线条图案

- (void)setMinimumTrackImage:(UIImage *)image forState:(UIControlState)state;

设置滑块未划过部分的线条图案

- (void)setMaximumTrackImage:(UIImage *)image forState:(UIControlState)state;

对应的几个get方法

- (UIImage *)thumbImageForState:(UIControlState)state;
- (UIImage *)minimumTrackImageForState:(UIControlState)state;
- (UIImage *)maximumTrackImageForState:(UIControlState)state;

对应的设置当前状态的响应属性的方法

@property(nonatomic,readonly) UIImage* currentThumbImage;
@property(nonatomic,readonly) UIImage* currentMinimumTrackImage;
@property(nonatomic,readonly) UIImage* currentMaximumTrackImage;

//初始化
mySlider = [[UISlider alloc] initWithFrame:(CGRect){,,,}];
//最小边界值
mySlider.minimumValue = ;
//最大边界值
mySlider.maximumValue = ;
//这个值是介于滑块的最大值和最小值之间的,如果没有设置边界值,默认为0-1
mySlider.value =0.5;
//设置滑块值是否连续变化(默认为YES)
mySlider.continuous= YES;
//设置滑块最左端显示的图片
mySlider.minimumValueImage = [UIImage imageNamed:@""];
//设置滑块最右端显示的图片
mySlider.maximumValueImage = [UIImage imageNamed:@""];
//设置滑块左边(小于部分)线条的颜色
mySlider.minimumTrackTintColor = [UIColor blueColor];
//设置滑块右边(大于部分)线条的颜色
mySlider.maximumTrackTintColor = [UIColor greenColor];
//设置滑块颜色(影响已划过一端的颜色)
mySlider.thumbTintColor = [UIColor grayColor];
//加入视图
[self.view addSubview:mySlider];
//添加点击事件
[mySlider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
 

二、UIProgressView

//初始化
progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
//加入视图
[self.view addSubview:progressView];
//设置位置,尺寸
progressView.frame = (CGRect){,,,};
//设置进度条颜色
progressView.trackTintColor = [UIColor blueColor];
//设置进度默认值,这个相当于百分比,范围在0~1之间,不可以设置最大最小值
progressView.progress = 0.1;
//设置进度条上进度的颜色
progressView.progressTintColor = [UIColor yellowColor];
//设置进度条的背景图片
progressView.trackImage = [UIImage imageNamed:@""];
//设置进度条上进度的背景图片
progressView.progressImage = [UIImage imageNamed:@""];
//设置进度值并动画显示
[progressView setProgress:0.7 animated:YES];

如图:

三、UISwich

UISwitch 的作用是给用户提供开关,在系统的设置界面很常见,控件也很简单。

常见属性:

1、onTintColor

开关开启状态时的颜色

2、tintColor

开关风格颜色

3、thumbTintColor

开关按钮颜色

4、BOOL on

开关的状态

  //初始化
swicthView = [[UISwitch alloc] initWithFrame:(CGRect){,,,}];
swicthView.on = YES;
//设置开关开启状态时的颜色
swicthView.onTintColor = [UIColor yellowColor];
//设置开关风格颜色
swicthView.tintColor = [UIColor blueColor];
//设置开关按钮颜色
swicthView.thumbTintColor = [UIColor purpleColor];
//设置开关开启状态时的图片
swicthView.onImage = [UIImage imageNamed:@"pic1"];
//设置开关关闭状态时的图片
swicthView.offImage = [UIImage imageNamed:@"pic2"];
//加入视图
[self.view addSubview:swicthView];

添加监听事件:

 [swicthView addTarget:self action:@selector(swicthAction:) forControlEvents:UIControlEventValueChanged];

 - (void)swicthAction:(UISwitch *)mySwicth{
UILabel *lastLabel = (UILabel*)[self.view viewWithTag:];
[lastLabel removeFromSuperview]; UISwitch *switchButton = mySwicth;
BOOL isButtonOn = [switchButton isOn]; UILabel *switchLabel = [[UILabel alloc] initWithFrame:(CGRect){,,,}];
switchLabel.font = [UIFont systemFontOfSize:];
switchLabel.tag = ;
[self.view addSubview:switchLabel];
if (isButtonOn) {
switchLabel.text = @"是";
}else
switchLabel.text = @"否";
}

ios基础篇(七)——UISwich、UISlider、UIProgressView的用法总结的更多相关文章

  1. ios基础篇(十六)——UIWebView的基本使用

    UIWebView是内置的浏览器控件,可以用它来浏览网页.打开文档等.UIWebView是一个混合体,具体的功能控件内置的,实现一些基本的功能.UIWebView可以查看Html网页,pdf文件,do ...

  2. ios基础篇(三)——UIButton的详细介绍

    按钮UIButton是ios开发中最常见的控件之一,下面来介绍UIButton的详细内容: 一.UIButton的定义 UIButton *button=[[UIButton buttonWithTy ...

  3. Lua 学习之基础篇七<Lua Module,Package介绍>

    Lua 之Module介绍 包管理库提供了从 Lua 中加载模块的基础库. 只有一个导出函数直接放在全局环境中: [require]. 所有其它的部分都导出在表 package 中. require ...

  4. ios基础篇(二十九)—— 多线程(Thread、Cocoa operations和GCD)

    一.进程与线程 1.进程 进程是指在系统中正在运行的一个应用程序,每个进程之间是独立的,每个进程均运行在其专用且受保护的内存空间内: 如果我们把CPU比作一个工厂,那么进程就好比工厂的车间,一个工厂有 ...

  5. ios基础篇(二十七)—— Json解析

    一.什么是Json JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.它基于ECMAScript的一个子集. JSON采用完全独立于语言的文本格式,但是也使 ...

  6. ios基础篇(二十六)—— UITableViewCell的分组索引与标记

    一.表视图的索引目录 首先要创建一个TableView,之前有说过,这里就不详细说了(参考前面第十四篇). 直接贴代码吧, #import "ViewController.h" @ ...

  7. ios基础篇(二十五)—— Animation动画(UIView、CoreAnimation)

    Animation主要分为两类: 1.UIView属性动画 2.CoreAnimation动画 一.UIView属性动画 UIKit直接将动画集成到UIView类中,实现简单动画的创建过程.UIVie ...

  8. ios基础篇(二十四)—— 文字、图片的绘制及其自定义Button

    这篇文章我们主要来拿官方的控件来研究一下,我们来仿照官方的控件,自己来实现它提供的控件: 首先来看看基本的图片与文字的绘制,很简单. 一.imageView 所有的视图都是继承自UIView,所以我们 ...

  9. ioS基础篇(十九)——UIResponder简析

    UIResponder类定义了对象相应和控制事件的接口,他是UIApplication.UIView的超类,这类的实例通常被称为应答对象. 一.Responder对象 在iOS系统中,能够响应并处理事 ...

随机推荐

  1. 线程入门之优先级priority

    package com.thread; /** * 优先级: * Thread.MAX_PRIORITY:最大优先级 10 * Thread.MIN_PRIORITY:最小优先级 1 * Thread ...

  2. NoSQL数据库的分布式模型

    NoSQL数据库的分布式模型 单一服务器 在一个服务器完全能够胜任工作时就没必要考虑分布式,这样部署简单,维护也方便很多: 分片 特点 数据的各个部分存放在集群的不同服务器中: 比如按字母来划分:以a ...

  3. Python基础学习笔记(五)常用字符串内建函数

    参考资料: 1. <Python基础教程> 2. http://www.runoob.com/python/python-strings.html 3. http://www.liaoxu ...

  4. STL--set

    set-概述: 集合Set是一个容器,它其中所包含的元素的值是唯一的.集合中的元素按一定的顺序排列,并被作为集合中的实例. 一个集合通过一个链表来组织,其具体实现采用了红黑树的平衡二叉树的数据结构. ...

  5. JZs3c2440学习笔记一

    1.连线 串口线usb-com,USB下载线 2.驱动安装 USB-serial,  dnw的sec s3c2410x test驱动安装(win7下安装方法搜索:百问网WIN7,64,dnw) 3.烧 ...

  6. iOS - Swift 与 Objective-C 互相操作

    前言 在 Swift 语言中,我们可以使用 Objective-C.C 语言编写代码,我们可以导入任意用 Objective-C 写的 Cocoa 平台框架.Objective-C 框架或 C 类库. ...

  7. 常用sql(转)

    1增 1.1[插入单行]insert [into] <表名> (列名) values (列值)例:insert into Strdents (姓名,性别,出生日期) values ('开心 ...

  8. ERROR 1201 (HY000) Could not initialize master info structure

    1.错误原因:Slave线程启动出现问题.2.解决办法一:stop slave; reset slave; start slave; show slave status\G3.如果解决方法一,还是失败 ...

  9. maven setting.xml配置说明

    文件存放位置 全局配置: ${M2_HOME}/conf/settings.xml 用户配置: ${user.home}/.m2/settings.xml note:用户配置优先于全局配置.${use ...

  10. mac homebrew PHP

    启动PHP p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px "Andale Mono"; color: #29f914; ...