UIButton属性

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个像素的距离。

给iOS开发新手送点福利,简述UIButton的属性和用法的更多相关文章

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

    1.+(BOOL)isSourceTypeAvailable:(UIImagePickerControllerSourceType)sourceType;         // 检查指定源是否在设备上 ...

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

    UITableView UITableView内置了两种样式:UITableViewStylePlain,UITableViewStyleGrouped   <UITableViewDataSo ...

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

    UIView 1.alpha 设置视图的透明度.默认为1. // 完全透明 view.alpha = 0; // 不透明 view.alpha = 1; 2.clipsToBounds // 默认是N ...

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

    UITextField属性 0.     enablesReturnKeyAutomatically 默认为No,如果设置为Yes,文本框中没有输入任何字符的话,右下角的返回按钮是disabled的. ...

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

    UILabel属性 1.text:设置标签显示文本. label.text = @"我是Label"; 2.attributedText:设置标签属性文本. NSString *t ...

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

    1.   numberOfComponents:返回UIPickerView当前的列数 NSInteger num = _pickerView.numberOfComponents; NSLog( @ ...

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

    UIScrollView 1.   contentOffset 默认CGPointZero,用来设置scrollView的滚动偏移量. // 设置scrollView的滚动偏移量 scrollView ...

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

    UIPageControl 1.   numberOfPages // 设置有多少页 默认为0 [pageControl setNumberOfPages:kImageCount]; 2.   cur ...

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

    UISegment属性 1.segmentedControlStyle 设置segment的显示样式. typedef NS_ENUM(NSInteger, UISegmentedControlSty ...

随机推荐

  1. install ros-indigo-ecl-build

    -- ==> add_subdirectory(bp_smart_charging/bp_dock_drive) CMake Warning at /opt/ros/indigo/share/c ...

  2. JSP 指令

    JSP 指令 JSP指令用来设置整个JSP页面相关的属性,如网页的编码方式和脚本语言. 语法格式如下: <%@ directive attribute="value" %&g ...

  3. Jenkins+Sonar集成对代码进行持续检测

    介绍 SonarQube(曾用名Sonar(声纳)[1])是一个开源的代码质量管理系统. 特征 支持超过25种编程语言[2]:Java.C/C++.C#.PHP.Flex.Groovy.JavaScr ...

  4. <<网络是怎样连接的>>笔记第2章用电信号传输Tcp/ip数据

    创建套接字: 协议栈的内部结构.套接字的实体,以及创建套接字的操作过程 连接服务器: “连接”具体是进行怎样的操作,在这个过程中协议栈到底是如何工作的, 以及客户端和服务器是如何进行交互的. 收发数据 ...

  5. Luogu P4062 [CTSC2018]混合果汁 (主席树)

    二分$d$, 转为判断判断是否能取到$Lj$升, 再可持久化一下就好了 #include <iostream> #include <algorithm> #include &l ...

  6. Leetcode 39

    //经典回溯法class Solution { public: vector<vector<int>> combinationSum(vector<int>& ...

  7. 本地Jdev Run PG报严重: Socket accept failed错误

    严重: Socket accept failed java.net.SocketException: select failed at java.net.PlainSocketImpl.socketA ...

  8. 本田CB750型加速时发动机工作间歇

    本田CB750型加速时发动机工作间歇 [故陣现象]近期以来,该车发动机工作无力,加速时发 动机工作不连续. [原因分析]起动发动机试验,发动机起动困难,怠速时 抖动严重,加速反应缓慢,工作间歇,声音沉 ...

  9. Springfox与swagger的整合使用(十七)

    一.前言 让我们先理一下springfox与swagger的关系. swagger是一个流行的API开发框架,这个框架以“开放API声明”(OpenAPI Specification,OAS)为基础, ...

  10. java-IO-基本输出输入流

    / 标准输入输出流: 直接类名调用 一经创建无法改变 public static final PrintStream err “标准”错误输出流. public static final InputS ...