UIButton头文件常见属性

1、属性

  • contentEdgeInsets: default is UIEdgeInsetsZero.设置内容四边距,默认边距为0

@property(nonatomic) UIEdgeInsets contentEdgeInsets

  • titleEdgeInsets: default is UIEdgeInsetsZero,文字内边距。默认边距为0.

@property(nonatomic) UIEdgeInsets titleEdgeInsets;

  • reversesTitleShadowWhenHighlighted: default is NO. if YES, shadow reverses to shift between engrave and emboss appearance。默认状态是 NO,按钮高亮时,阴影出现在相反位置。

@property(nonatomic) BOOL reversesTitleShadowWhenHighlighted;

  • imageEdgeInsets: default is UIEdgeInsetsZero。图片内边距,默认边距为0;

@property(nonatomic) UIEdgeInsets imageEdgeInsets;

  • adjustsImageWhenHighlighted : default is YES. if YES, image is drawn darker when highlighted(pressed),当按钮高亮时是否调整图片。默认是 YES

@property(nonatomic) BOOL adjustsImageWhenHighlighted;

  • adjustsImageWhenDisabled:default is YES. if YES, image is drawn lighter when disabled.默认是 yes,如果是 YES,图形绘制较轻时禁用

@property(nonatomic) BOOL adjustsImageWhenDisabled;

  • showsTouchWhenHighlighted:default is NO. if YES, show a simple feedback (currently a glow) while highlighted。默认是 NO,如果是 YES,在高亮期间显示一个简单的反馈(当前发光).如果没有高亮状态,不做任何反馈。

@property(nonatomic) BOOL showsTouchWhenHighlighted;

  • tintColor: The tintColor is inherited through the superview hierarchy. See UIView for more information.
    这个属性是从 UIView 继承过来的,更多解释信息见 UIView.该属性不应用于UIButtonTypeCustom.,如果Custom 类型的按钮需要使用该属性,应该重写该属性的 set方法。

@property(null_resettable, nonatomic,strong) UIColor *tintColor

  • buttonType:按钮样式属性,取值枚举类型

@property(nonatomic,readonly) UIButtonType buttonType;

  • currentTitle:normal/highlighted/selected/disabled. can return nil。获取当前的文本。

@property(nullable, nonatomic,readonly,strong) NSString *currentTitle;

  • currentTitleColor:normal/highlighted/selected/disabled. always returns non-nil. default is white(1,1)。当前文本颜色,默认白色。

@property(nonatomic,readonly,strong) UIColor *currentTitleColor;

  • currentTitleShadowColor:normal/highlighted/selected/disabled.当前状态下的文本阴影颜色

@property(nullable, nonatomic,readonly,strong) UIColor *currentTitleShadowColor;

  • currentImage:normal/highlighted/selected/disabled. can return nil。当前状态下的图片。

@property(nullable, nonatomic,readonly,strong) UIImage *currentImage;

  • currentBackgroundImage:normal/highlighted/selected/disabled. can return nil。当前状态下的背景图片

@property(nullable, nonatomic,readonly,strong) UIImage *currentBackgroundImage;

  • currentAttributedTitle:normal/highlighted/selected/disabled. can return nil。当前状态下的文本属性。

@property(nullable, nonatomic,readonly,strong) NSAttributedString *currentAttributedTitle;

  • titleLabel:文本标签属性

@property(nullable, nonatomic,readonly,strong) UILabel *titleLabel;

  • imageView:图片属性

@property(nullable, nonatomic,readonly,strong) UIImageView *imageView;

2、方法

由于按钮是有状态的,比如:未点击状态,高亮状态,选中状态,不可用状态等。所以按钮所提供的方法当中很多是根据按钮状态来设置的。
  • buttonWithType::类方法,创建按钮对象时,直接指定按钮类型。取值为枚举。

+ (instancetype)buttonWithType:(UIButtonType)buttonType;

  • setTitle:forState::default is nil. title is assumed to be single line。根据按钮状态设置文字。

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

  • setTitleColor:forState::default if nil. use opaque white。根据按钮状态设置文字颜色,默认白色。

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

  • setTitleShadowColor: forState: : default is nil. use 50% black。 设置文字阴影颜色,默认半透明黑色

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

  • setImage: forState: : default is nil. should be same size if different for different states。根据按钮状态设置图片。

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

  • setBackgroundImage: forState: : 根据按钮状态设置背景图片。

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

  • setAttributedTitle: forState: : default is nil. title is assumed to be single line.根据按钮状态设置文本属性内容(包括文字大小,颜色等)。假设文字是单行的。

- (void)setAttributedTitle:(nullable NSAttributedString *)title forState:(UIControlState)state;

  • titleForState: forState: :these getters only take a single state value。根据按钮状态获取文本

- (nullable NSString *)titleForState:(UIControlState)state;

  • titleColorForState: forState: : 根据按钮状态获取文本颜色

- (nullable UIColor *)titleColorForState:(UIControlState)state;

  • titleShadowColorForState: forState: : 根据按钮状态获取文本阴影颜色

- (nullable UIColor *)titleShadowColorForState:(UIControlState)state;

  • imageForState: forState: : 根据按钮状态获取图片。

- (nullable UIImage *)imageForState:(UIControlState)state;

  • backgroundImageForState: forState: : 根据按钮状态获取背景图片。

- (nullable UIImage *)backgroundImageForState:(UIControlState)state;

  • attributedTitleForState: forState: : 根据按钮状态获取文本属性。

- (nullable NSAttributedString *)attributedTitleForState:(UIControlState)state;

  • backgroundRectForBounds: : 自定义按钮时,可以更改背景图片在按钮当中的位置。

- (CGRect)backgroundRectForBounds:(CGRect)bounds;

  • contentRectForBounds: : 自定义按钮时,可以更改整个内容在按钮当中的位置。

- (CGRect)contentRectForBounds:(CGRect)bounds;

  • titleRectForContentRect: : 自定义按钮时,可以更改Label在按钮当中的位置。

- (CGRect)titleRectForContentRect:(CGRect)contentRect;

  • imageRectForContentRect: : 自定义按钮时,可以更改图片在按钮当中的位置。

- (CGRect)imageRectForContentRect:(CGRect)contentRect;

UIButton 头文件常见属性和方法的更多相关文章

  1. UILabel头文件常见属性

    text : default is nil 文本属性,默认值是 nil @property(nullable, nonatomic,copy) NSString *text; font : defau ...

  2. Xcode增加头文件搜索路径的方法

    Xcode增加头文件搜索路径的方法 以C++工程为例: 在Build Settings 页面中的Search Paths一节就是用来设置头文件路径. 相关的配置项用红框框起来了,共有三个配置项: He ...

  3. C/C++避免头文件重复包含的方法

    C/C++避免头文件重复包含的方法 1. #ifndef 2. #pragma once 3. 混合使用 在实际的编程过程中,因为会使用多个文件,所以在文件中不可避免的要引入一些头文件,这样就可能会出 ...

  4. IAR for MSP430 关于添加自定义头文件的两种方法【转】

    前言:第一次接触这个软件,编译一个例程一直出现没有包含头文件的错误,在网上找了好几个方法都没什么效果,看到了篇文章,利用里面的方法1解决了,特此复制下来保存学习用. 原文链接:https://blog ...

  5. 详解keil采用C语言模块化编程时全局变量、结构体的定义、声明以及头文件包含的处理方法

    一.关于全局变量的定义.声明.引用: (只要是在.h文件中定义的变量,然后在main.c中包含该.h文件,那么定义的变量就可以在main函数中作为全局变量使用) 方法1: 在某个c文件里定义全局变量后 ...

  6. keil采用C语言模块化编程时全局变量、结构体的定义、声明以及头文件包含的处理方法

    以前写单片机程序时总是把所用函数和变量都写在一个c文件里,后来遇到大点的项目,程序动则几千行,这种方式无疑会带来N多麻烦,相信大家都有所体验吧! 后来学会了在keil里进行模块化编程,即只把功能相同或 ...

  7. Viewing the interface of your Swift code,查看Swift代码的头文件的三种方法

      Technical Q&A QA1914 Viewing the interface of your Swift code Q:  How do I view the interface ...

  8. 第9.10节 Python中IO模块其他文件操作属性和方法简介

    本文中所有案例中的fp都是使用open函数打开文件返回的一个文件对象,为了节省篇幅,大部分没有提供文件打开的代码. 一. 文件是否关闭的属性 属性名:closed 功用:判断文件是否关闭 示例: &g ...

  9. UIButton常见属性和方法

    一.创建,两种方法: 1. 常规的 initWithFrame UIButton *btn1 = [[UIButton alloc]initWithFrame:CGRectMake(10, 10, 8 ...

随机推荐

  1. 【转换模型+扫描线】【UVA1398】Meteor

    The famous Korean internet company nhn has provided an internet-based photo service which allows The ...

  2. mysql开启慢查询日志

    5.1版本之前,在 my.cnf添加如下信息, long_query_time=1 log_slow_queries=/data/mysql/slow.log 5.1版本之后,在 my.cnf添加如下 ...

  3. stagefright框架(七)-Audio和Video的同步

    讲完了audio和video的处理流程,接下来要看的是audio和video同步化(synchronization)的问题.OpenCORE的做法是设置一个主clock,而audio和video就分别 ...

  4. WinForm RDLC SubReport Step by step

    最近在做的一个PO管理系统,因为要用到订单打印,没有用水晶报表,直接使用VS2010的Reporting.参考了网上的一些文章,但因为找到的数据是用于WebForm的,适配到WinForm有点区别,竟 ...

  5. linux学习笔记之线程同步机制

    一.基础知识. 1:线程同步机制:互斥量,读写锁,条件变量,自旋锁,屏障. 1,互斥量:每个进程访问被互斥量保护的资源时,都需要先对互斥量进行判断. 1)互斥量重要属性:进程共享属性,健壮属性,类型属 ...

  6. 在VMware中为CentOS配置静态ip并可访问网络-Windows下的VMware

    在VMware中为CentOS配置静态ip并可访问网络-Windows下的VMware 首先确保虚拟网卡(VMware Network Adapter VMnet8)是开启的,然后在windows的命 ...

  7. 今年暑假不AC(贪心)

    今年暑假不AC 点我 Problem Description “今年暑假不AC?”“是的.”“那你干什么呢?”“看世界杯呀,笨蛋!”“@#$%^&*%...” 确实如此,世界杯来了,球迷的节日 ...

  8. Oracle EBS-SQL (PO-13):检查采购物料无一揽子协议价格.sql

    Select        msi.segment1                               物料编码,       msi.DESCRIPTION                 ...

  9. QT VS配置UNICODE问题

    默认情况下,使用VSQT插件 导入.pro后,会自动在项目文件里面预定义好宏UNICODE,可以把该宏去掉,以免造成其他程序,使用多字节的代码出错 去除的两个方法 1.打开Propject->P ...

  10. D、GO、Rust 谁会在未来取代 C?为什么?——Go语言的定位非常好,Rust语言非常优秀,D语言也不错

    不要管我的地位和 D 语言创造者之一的身份.我会坦诚的回答这个问题.我熟悉 Go 和 Rust,并且知道 D 的缺点在哪里.我鼓励人们在 Rust 和 Go 社区相似身份的人,也可以提出他们诚恳的观点 ...