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的更多相关文章

  1. UI通过UISlider编写游戏第六感

    #import "RootViewController.h" @interface RootViewController (){    UILabel *scoreLabel; } ...

  2. ReactiveCocoa代码实践之-UI组件的RAC信号操作

    上一节是自己对网络层的一些重构,本节是自己一些代码小实践做出的一些demo程序,基本涵盖大多数UI控件操作. 一.用UISlider实现调色板 假设我们现在做一个demo,上面有一个View用来展示颜 ...

  3. UI--普通控件总结1--控件使用

    本文目录 0.UIView常用的属性和操作 0_1.UIView常见的属性 0_2.UIView状态 0_3.UIView常用的方法 1.文本框UITextField和文本视图UITextView 1 ...

  4. iOS学习24之UIControl及其子类

    1. UIControl初识 1> 概述 UIControl是有控制功能的视图( 如UIButton.UISlider.UISegmentedControl等)的父类 只要跟控制有关的控件都是继 ...

  5. IOS的UI总结

    一.UIView常见属性 1.frame  位置和尺寸(以父控件的左上角为原点(0,0)) 2.center 中点(以父控件的左上角为原点(0,0)) 3.bounds  位置和尺寸(以自己的左上角为 ...

  6. 【IOS笔记】About Events in iOS

    About Events in iOS Users manipulate their iOS devices in a number of ways, such as touching the scr ...

  7. iOS学习之UIControl

    一.UIControl初识      1.UIControl是有控制功能的视图(比如UIButton.UISlider.UISegmentedControl等)的父类. 只要跟控制有关的控件都是继承于 ...

  8. iOS开发——设备篇Swift篇&判断设备类型

    判断设备类型   1,分割视图控制器(UISplitViewController) 在iPhone应用中,使用导航控制器由上一层界面进入下一层界面. 但iPad屏幕较大,通常使用SplitViewCo ...

  9. 【转】iOS 开发怎么入门?

    原文网址:http://www.zhihu.com/question/20264108 iOS 开发怎么入门? 请问有设计模式.内存管理方面的资料吗?最好有除了官方文档之外的其它内容,10 条评论 分 ...

随机推荐

  1. nginx教程从入门到精通

    [转]nginx教程从入门到精通 nginx教程写了一段时间,无意中发现,nginx相关文章已经达到了近100篇了.觉得很有必要汇总到一起,它是我们运维生存时间的一片心血,他是学习nginx的同学必看 ...

  2. 合并百度影音的离线数据 with python 第二版 基于yield

    重新整理了一下代码. 增加了bdv,mkv的处理流程. 目前暂时支持windows平台. bdv,mkv,rmvb的不同处理流程 # -*- coding: UTF-8 -*- import os i ...

  3. 【分享】iTOP-iMX6UL开发板驱动看门狗 watchdog 以及 Linux-c 测试例程

    iTOP-iMX6UL开发板看门狗测试例程,iTOP-iMX6UL 开发板的看门狗驱动默认已经配置,可以直接使用测试例程. 版本 V1.1:1.格式修改:2.例程修改完善,其中增加喂狗代码.1 看门狗 ...

  4. Java软件开发不同薪资级别-技术要求

    15~20万 WEB应用服务器(Tomcat.Weblogic.Jetty.JBoss.WebSphere) NoSQL(Redis.MongoDB.HBase.Memcache) 消息中间件(Kaf ...

  5. CREATE FUNCTION - 定义一个新函数

    SYNOPSIS CREATE [ OR REPLACE ] FUNCTION name ( [ argtype [, ...] ] ) RETURNS rettype { LANGUAGE lang ...

  6. bash之数组

    Bash 提供索引和联想的一维数组变量.可用作任何变量 索引的数组 :内置的声明将显式声明数组.有没有最大限制 一个数组,也没有要求成员将索引或连续分配的大小.索引的数组 引用使用 (包括算术表达式) ...

  7. ActiveX控件获取不到对象属性或者方法的原因分析

    1.找不到调用的DLL或程序: 2.调用控件方法名称,与定义的函数名称不符合: 3.如果是网站网页调用ActiveX,检查控件是否添加安全对象: 4.如果是网站网页调用ActiveX,检查网页是否加入 ...

  8. 工具:docs网页笔记

    用到工具python 网页笔记工具:mkdocs https://www.cnblogs.com/bigmagic/p/10309260.html 案例: https://github.com/zha ...

  9. No-5.变量的命名

    变量的命名 目标 标识符和关键字 变量的命名规则 0.1 标识符和关键字 1.1 标识符 标示符就是程序员定义的 变量名.函数名 名字 需要有 见名知义 的效果 标示符可以由 字母.下划线 和 数字  ...

  10. python 调用exe程序

    #!/usr/bin/python #-*- coding:utf-8 -*- import os, subprocess import tkMessageBox import msg_box def ...