UIButton和UISlider
UIButton
主要功能:按钮控件,主要用于与用户操作进行交互
经常使用属性及方法
系统内建的按钮类型
UIButtonTypeCustom
UIButtonTypeSystem
UIButtonTypeDetaiDislosure
UIButtonTypeInfoLight
UIButtonTypeContactAdd
UIButtonTypeRoundedRect
系统中关于控件的状态类型
UIControlStateNormol
UIControlStateHighlighted
UIControlStateDisabled
UIControlStateSelected
UIControlStateApplication
UIControlStateReserved
几种常见设置UIButton方法
//依据UIButtonType创建不同天系统内建风格的按钮
+ (id)buttonWithType:(UIButtonType)buttonType;
eg:UIButton *button = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
//依据按钮状态设置按钮的标题
- (void)setTitle:(NSString *)title forState:(UIControlState)state;
[button setTitle:@"BTN" forState:UIControlStateNormal];
//依据按钮状态设置按钮上的文字颜色
- (void)setTitleColor:(UIColor *)color forState:(UIControlState)state;
eg:[button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
//依据按钮状态设置按钮的图片
- (void)setImage:(UIImage *)image forState:(UIControl)
eg:[button setImage:[UIImage imageNamed:@"xiaogou.jpg"] forState:UIControlStateNormal];
//依据按钮状态设置背景图片
- (void)setBackgroundImage:(UIImage *)image forState:(UIControlState)state
eg:[button setBackgroundImage:[UIImage imageNamed:@"xiaogou.jpg"] forState:UIControlStateNormal];
//给按钮加入目标及行为
- (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents
eg:[button addTarget:self action:@selector(onButton) forControlEvents:UIControlEventTouchUpInside];
UISlider
主要功能:滑块属性。用于控制某一范围内值得设置。如声音大小控制,音乐播放进度。
经常使用属性和方法:
@property(nonatomic) float value;//在某一时刻或者某一位置UISlider所表示的值,默认是0.0
NSLog(@"%f",self.slider.value);
@property(nonatomic) float minimumValue;//UISlider坐标是范围的最小值。
默认是0.0
NSLog(@"%f",self.slider.minimumValue);
@property(nonatomic) float maximumValue;//UISlider所表示范围的最大值,默认是1.0
//最小值时的图片,在UISlider的左边。默认是nil
@property(nonatomic, retain) UIImage *minimumValueImage;
self.slider.minimumValueImage = [UIImage imageNamed:@"xiaogou.jpg"];
//最大值是的图片,在UISlider的右边,默认是nil
@property(nonatomic, retain) UIImage *maximumValueImage;
self.slider.maximumValueImage = [UIImage imageNamed:@"xiaogou.jpg"];
//设置UISlider对象的值
- (void) setValue:(float)value animated:(BOOL)animated;
- //让滑块以一定的速度自己主动滑动
代码演示:
让滑块自己主动的以一定的速度滑动
#import "ViewController.h"
@interface ViewController ()
@property (weak,nonatomic) UISlider *slider;//滑块控件是拖拽过来的
@end
@implementation ViewController
- (void)viewDidLoad {
self.slider.minimumValue = 0.0;
self.slider.maximumValue = 1000.0;
self.slider.minimumTrackTintColor = [UIColor redColor];
self.slider.maximumTrackTintColor = [UIColor greenColor];
self.slider.thumbTintColor = [UIColor purpleColor];
UIButton *btnType = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btnType.backgroundColor = [UIColor blueColor];
btnType.frame = CGRectMake(100,300,100,60);
[self.view addSubview:btnType];
- (void)onTimer:(NSTimer *)timer
{
static float value = 10;
value +=5;
[self.slider setValue:value animated:YES];
NSLog(@"%f",self.slider.value);
}
- (void)onButton{
[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(onTimer:) userInfo:nil repeats:NO];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
}
UIButton和UISlider的更多相关文章
- UI通过UISlider编写游戏第六感
#import "RootViewController.h" @interface RootViewController (){ UILabel *scoreLabel; } ...
- ReactiveCocoa代码实践之-UI组件的RAC信号操作
上一节是自己对网络层的一些重构,本节是自己一些代码小实践做出的一些demo程序,基本涵盖大多数UI控件操作. 一.用UISlider实现调色板 假设我们现在做一个demo,上面有一个View用来展示颜 ...
- UI--普通控件总结1--控件使用
本文目录 0.UIView常用的属性和操作 0_1.UIView常见的属性 0_2.UIView状态 0_3.UIView常用的方法 1.文本框UITextField和文本视图UITextView 1 ...
- iOS学习24之UIControl及其子类
1. UIControl初识 1> 概述 UIControl是有控制功能的视图( 如UIButton.UISlider.UISegmentedControl等)的父类 只要跟控制有关的控件都是继 ...
- IOS的UI总结
一.UIView常见属性 1.frame 位置和尺寸(以父控件的左上角为原点(0,0)) 2.center 中点(以父控件的左上角为原点(0,0)) 3.bounds 位置和尺寸(以自己的左上角为 ...
- 【IOS笔记】About Events in iOS
About Events in iOS Users manipulate their iOS devices in a number of ways, such as touching the scr ...
- iOS学习之UIControl
一.UIControl初识 1.UIControl是有控制功能的视图(比如UIButton.UISlider.UISegmentedControl等)的父类. 只要跟控制有关的控件都是继承于 ...
- iOS开发——设备篇Swift篇&判断设备类型
判断设备类型 1,分割视图控制器(UISplitViewController) 在iPhone应用中,使用导航控制器由上一层界面进入下一层界面. 但iPad屏幕较大,通常使用SplitViewCo ...
- 【转】iOS 开发怎么入门?
原文网址:http://www.zhihu.com/question/20264108 iOS 开发怎么入门? 请问有设计模式.内存管理方面的资料吗?最好有除了官方文档之外的其它内容,10 条评论 分 ...
随机推荐
- [翻译] API测试最佳实践 - 身份验证(Authentication)
API测试最佳实践 - 身份验证 适用等级:高级 1. 概况 身份验证通常被定义为是对某个资源的身份的确认的活动,这里面资源的身份指代的是API的消费者(或者说是调用者).一旦一个用户的身份验证通过了 ...
- Node.js——body方式提交数据
引入核心模块 http,利用其 api(http.createServer) 返回一个 http.server 实例,这个实例是继承于net.Server,net.Server 也是通过net.cre ...
- 迅为iTOP-4418嵌入式开发板初体验
iTOP-4418开发板预装 Android4.4.4 系统, 支持9.7 寸.7 寸.4.3 寸屏幕. 参数:核心板参数 尺寸 50mm*60mm高度 核心板连接器为1.5mmCPU ARM Cor ...
- Shiro的subject实质上是当前执行用户的特定视图。
Shiro的subject实质上是当前执行用户的特定视图. 通过org.apache.shiro.SecurityUtils可以查询当前执行用户: Subject currentUser = Secu ...
- POJ中和质数相关的三个例题(POJ 2262、POJ 2739、POJ 3006)
质数(prime number)又称素数,有无限个.一个大于1的自然数,除了1和它本身外,不能被其他自然数整除,换句话说就是该数除了1和它本身以外不再有其他的因数:否则称为合数. 最小的质数 ...
- 第2节 hive基本操作:9、hive当中创建外部表的语法及外部表的操作&分区表的语法和操作
外部表: 外部表说明: 外部表因为是指定其他的hdfs路径的数据加载到表当中来,所以hive表会认为自己不完全独占这份数据,所以删除hive表的时候,数据仍然存放在hdfs当中,不会删掉 管理表和外部 ...
- 【2019 1月集训 Day1】回文的后缀
题意: 给定 n,s,求有多少个字符集大小为 s ,长度为 n 的字符串,使得其不存在一个长度大于 1 的回文后缀. 答案对 m 取模. 分析: 考场见到计数题的链式反应,想写暴力—>暴力难写— ...
- [Luogu] P4838 P哥破解密码
题目背景 P哥是一个经常丢密码条的男孩子. 在ION 8102赛场上,P哥又弄丢了密码条,笔试满分的他当然知道这可是要扣5分作为惩罚的,于是他开始破解ION Xunil系统的密码. 题目描述 定义一个 ...
- SVN CommandLine
要是SVN命令行用不了的话: 1.SVN装了没? 2.SVN安装时,选项“command line client tools”选了没. 检出: svn checkout [-depth ARG] [- ...
- php 实现301重定向跳转实例代码
本文主要介绍php 实现301重定向跳转,通过实例代码让大家更好的理解重定向的方法,有需要的小伙伴可以参考下 在php中301重定向实现方法很简单我们只要简单的利用header发送301状态代码,然后 ...