1.UIButton状态:

UIControlStateNormal          // 正常状态   
UIControlStateHighlighted     // 高亮状态   
UIControlStateDisabled        // 禁用状态    
UIControlStateSelected        // 选中状态    
UIControlStateApplication     //     
UIControlStateReserved        // 保留状态

2.Uibutton类型:

UIButtonTypeCustom            //自定义类型
添加图片:

灰色背景颜色:


UIButtonTypeRoundedRect       //圆角类型


UIButtonTypeDetailDisclosure   //细节展示按钮


UIButtonTypeInfoLight          //浅色背景的信息按钮


UIButtonTypeInfoDark           //暗色背景的信息按钮


UIButtonTypeContactAdd         // 添加按钮


3.UIButton常用属性

给按钮设置文字时,苹果文档说明,不能使用label对象设置文字的颜色或者阴影颜色,相反必须使用setTitleColor:forState: and setTitleShadowColor:forState:这两个方法才能修改这些值。

设置按钮中其他属性依次类推。。。。

//设置对应状态的标题内容default is nil. title is assumed to be single line

- (void)setTitle:(NSString *)title forState:(UIControlState)state;

//设置对应状态的标题颜色

- (void)setTitleColor:(UIColor *)color forState:(UIControlState)state;

//设置对应状态的标题阴影颜色

- (void)setTitleShadowColor:(UIColor *)color forState:(UIControlState)state;

//设置对应状态的按钮的图片

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

//设置对应状态的按钮背景图片

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

添加事件

- (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents;

这些事件都是基于触摸、基于值、基于编辑。有如下事件会触发。

在点击按钮是按钮是凹下去,然后弹起才触发起事件,按钮的状态有:

  1. UIControlEventTouchDown      // 按下
  2. UIControlEventTouchDownRepeat  多次按下
  3. UIControlEventTouchUpInside // 在按钮及其一定外围内松开
  4. UIControlEventTouchUpOutside // 按钮外面松开

4.adjustsImageWhenDisabled

当按钮禁用的情况下,图像的颜色会被画深一点,默认为YES。

5.adjustsImageWhenHighlighted

当按钮高亮的情况下,图像的颜色会被画深一点,默认为YES。

6.showsTouchWhenHighlighted

button.showsTouchWhenHighlighted=YES;点击时的闪光效果会被前景图片遮住中间部分;

6.contentEdgeInsets

设置按钮的内部内容(包含按钮图片和标题)离按钮边缘上下左右的距离。

7.按钮实例

1.有些时候我们想让UIButton的title居左对齐,我们设置 
btn.textLabel.textAlignment
= UITextAlignmentLeft

是没有作用的,我们需要设置

btn.contentHorizontalAlignment = UIControlContentHorizonAlignmentLeft;

但是问题又出来,此时文字会紧贴到左边框,我们可以设置

btn.contentEdgeInsets = UIEdgeInsetsMake(0,10, 0, 0);

使文字距离左边框保持10个像素的距离。

UIButton属性的更多相关文章

  1. 基本控件文档-UIButton属性

    CHENYILONG Blog 基本控件文档-UIButton属性 Fullscreen UIButton属性技术博客http://www.cnblogs.com/ChenYilong/ 新浪微博ht ...

  2. 基本控件文档-UIButton属性---iOS-Apple苹果官方文档翻译

    本系列所有开发文档翻译链接地址:iOS7开发-Apple苹果iPhone开发Xcode官方文档翻译PDF下载地址 //转载请注明出处--本文永久链接:http://www.cnblogs.com/Ch ...

  3. iOS -Swift 3.0 -UIButton属性大全

    // //  ViewController.swift //  Swift-UIButton // //  Created by luorende on 16/9/9. //  Copyright © ...

  4. 给iOS开发新手送点福利,简述UIButton的属性和用法

    UIButton属性 1.UIButton状态: UIControlStateNormal          // 正常状态    UIControlStateHighlighted     // 高 ...

  5. UIButton无法响应点击事件

    一.问题描述 因为项目需要,需要UITableView上添加固定的筛选表头,一直固定,不能随UITableView滚动.所以直接将表头与UITableView分离,将它添加到控制器的UIView上,即 ...

  6. iOS-开发日志-UIButton

    UIButton属性 1.UIButton状态: UIControlStateNormal          // 正常状态    UIControlStateHighlighted     // 高 ...

  7. iOS-UI控件之UIButton

    ---恢复内容开始--- UIButton 既可以显示图片,又可以显示文字,还能随时调整内部位置 系统自带尺寸 storyboard内部调整UIButton属性 状态 监听按钮点击事件 凡是继承自UI ...

  8. Ngui 五种点击事件实现方式及在3d场景中点透的情况

    http://www.unity蛮牛.com/thread-22018-1-1.html ngui作为unity界面插件之一中,无疑是最好用,使用最多的了从自学unity到现在界面一直使用它 由于它的 ...

  9. Swift 简单的通讯录

    Swift 通讯录实战 1.功能需求 整个项目由三个界面构成:首页面(全部联系人),添加联系人界面和联系人详情界面 整个项目使用纯代码编程 数据处理方面使用一个工具类,处理所有数据的增删改查. 首页由 ...

随机推荐

  1. virtualenv -- python虚拟沙盒

    有人说:virtualenv.fabric 和 pip 是 pythoneer 的三大神器. 不管认不认同,至少要先认识一下,pip现在倒是经常用到,virtualenv第一次听说,不过,总得尝试一下 ...

  2. communication between threads 线程间通信 Programming Concurrent Activities 程序设计中的并发活动 Ada task 任务 Java thread 线程

    Computer Science An Overview _J. Glenn Brookshear _11th Edition activation 激活 parallel processing 并行 ...

  3. android文字阴影效果(转)

    关于android文字阴影,共有四个属性可以设置: android:shadowColor :阴影颜色 android:shadowDx :阴影x方向位移 android:shadowDy :阴影y方 ...

  4. js 键盘移动div、img对象

    js 键盘移动div.img对象 <html> <script type="text/javascript"> var EXtype="" ...

  5. WCF TCP 错误代码 10061: 由于目标计算机积极拒绝

    表象是连不上服务端,本质原因多种多样,网络硬件问题导致的网络不通.服务本身问题或没有启动.或者防火墙阻隔等等不一而足. 1.ping看服务端能否ping通: 2.telnet ip地址 端口 ,看看是 ...

  6. iOS开发教程之:iPhone开发环境搭建

    安装条件: 硬件:一台拥有支持虚拟技术的64位双核处理器和2GB以上内存的PC. 注意:运行MAC OS,需要电脑支持虚拟技术(VT),安装时,需要将VT启动,在BIOS中开启. 软件: Window ...

  7. xcode5 和code6中push后方法执行的先后问题

    在xocde5中 执行的顺序是 prepareForSegue  .viewDidLoad. didSelectRowAtIndexPath,在xcode6中 执行的顺序是  prepareForSe ...

  8. 转: .NET MVC3 几种返回 JSON 对象的方式和注意事项

    .NET MVC3 几种返回 JSON 对象的方式和注意事项 转自:http://blog.csdn.net/xxj_jing/article/details/7382589 引言在用 .NET MV ...

  9. [LeetCode]题解(python):089 Gray Code

    题目来源 https://leetcode.com/problems/gray-code/ The gray code is a binary numeral system where two suc ...

  10. leetcode:Valid Parentheses

    括号匹配 Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the ...