UIButton常用属性和函数详解
来源:互联网 发布:淘宝注册手机号上限 编辑:程序博客网 时间:2024/06/05 18:09
特常用的属性说明:
UIButton内有两个控件titleLabel和imageView,可以用来显示一个文本和图片,给UIButton设置了title和image后,图片在左边,文本在图片右边显示,它们两个做为一个整体依赖于button的contentHorizontalAlignment居左居右或居中显示。
1.当button.width < image.width时,只显示被压缩后的图片,图片是按fillXY的方式压缩。
2.当button.width > image.width,且 button.width < (image.width + text.width)时,图片正常显示,文本被压缩。
3.当button.width > (image.width + text.width),两者并列默认居中显示,可通过button的属性contentHorizontalAlignment改变水平对齐方式。
想两改变两个子控件的显示位置,可以分别通过setTitleEdgeInsets和setImageEdgeInsets来实现。需要注意的是,对titleLabel和imageView设置偏移,是针对它当前的位置起作用的,并不是针对它距离button边框的距离的。
一、属性
- contentEdgeInsets: default is UIEdgeInsetsZero.设置内容四边距,默认边距为0
- titleEdgeInsets: default is UIEdgeInsetsZero,文字内边距。默认边距为0.
- reversesTitleShadowWhenHighlighted: default is NO. if YES, shadow reverses to shift between engrave and emboss appearance。默认状态是 NO,按钮高亮时,阴影出现在相反位置。
- imageEdgeInsets: default is UIEdgeInsetsZero。图片内边距,默认边距为0;
- adjustsImageWhenHighlighted : default is YES. if YES, image is drawn darker when highlighted(pressed),当按钮高亮时是否调整图片。默认是 YES
- adjustsImageWhenDisabled:default is YES. if YES, image is drawn lighter when disabled.默认是 yes,如果是 YES,图形绘制较轻时禁用
- showsTouchWhenHighlighted:default is NO. if YES, show a simple feedback (currently a glow) while highlighted。默认是 NO,如果是 YES,在高亮期间显示一个简单的反馈(当前发光).如果没有高亮状态,不做任何反馈。
- tintColor: The tintColor is inherited through the superview hierarchy. See UIView for more information. 这个属性是从 UIView 继承过来的,更多解释信息见 UIView.该属性不应用于UIButtonTypeCustom.,如果Custom 类型的按钮需要使用该属性,应该重写该属性的 set方法。
- buttonType:按钮样式属性,取值枚举类型
- currentTitle:normal/highlighted/selected/disabled. can return nil。获取当前的文本。
- currentTitleColor:normal/highlighted/selected/disabled. always returns non-nil. default is white(1,1)。当前文本颜色,默认白色。
- currentTitleShadowColor:normal/highlighted/selected/disabled.当前状态下的文本阴影颜色
- currentImage:normal/highlighted/selected/disabled. can return nil。当前状态下的图片。
- currentBackgroundImage:normal/highlighted/selected/disabled. can return nil。当前状态下的背景图片
- currentAttributedTitle:normal/highlighted/selected/disabled. can return nil。当前状态下的文本属性。
- titleLabel:文本标签属性
- imageView:图片属性
二、 方法
由于按钮是有状态的,比如:未点击状态,高亮状态,选中状态,不可用状态等。所以按钮所提供的方法当中很多是根据按钮状态来设置的。- buttonWithType:类方法,创建按钮对象时,直接指定按钮类型。取值为枚举。
- setTitle:forState:default is nil. title is assumed to be single line。根据按钮状态设置文字。
- setTitleColor:forState:default if nil. use opaque white。根据按钮状态设置文字颜色,默认白色。
- setTitleShadowColor: forState: default is nil. use 50% black。 设置文字阴影颜色,默认半透明黑色
- setImage: forState: :default is nil. should be same size if different for different states。根据按钮状态设置图片
- setBackgroundImage: forState: 根据按钮状态设置背景图片
- setAttributedTitle: forState : default is nil. title is assumed to be single line.根据按钮状态设置文本属性内容(包括文字大小,颜色等)。假设文字是单行的
- titleForState: these getters only take a single state value。根据按钮状态获取文本
- titleColorForState: 根据按钮状态获取文本颜色
- titleShadowColorForState: 根据按钮状态获取文本阴影颜色
- imageForState: 根据按钮状态获取图片
- backgroundImageForState: 根据按钮状态获取背景图片
- attributedTitleForState: 根据按钮状态获取文本属性
- backgroundRectForBounds: :自定义按钮时,可以更改背景图片在按钮当中的位置
- contentRectForBounds: 自定义按钮时,可以更改整个内容在按钮当中的位置
- titleRectForContentRect: 自定义按钮时,可以更改Label在按钮当中的位置
- imageRectForContentRect: 自定义按钮时,可以更改图片在按钮当中的位置
0 0
- UIButton常用属性和函数详解
- UIButton常用方法和属性
- IOS--UIButton的常用属性和方法
- UIButton常用属性
- UIButton的常用属性
- UIButton常用属性
- UIButton常用属性总结
- UIButton属性详解
- IOS开发总结之UIButton常用属性和方法
- UITextField和UIButton属性
- UIButton常用属性介绍lzp
- ios UIButton的常用属性
- UIButton的常用属性设置
- UIView常用属性和函数
- UILabel和UIButton的属性
- iOS按钮UIButton常用属性总结
- 设置UIButton的一些常用属性
- UIView UILabel UITextField UIButton UIImageView 常用属性
- 剑指offer(52):字符串转为数字
- Jquery属性选择器
- Android下多进程访问SharedPreferences遇到的坑
- ps 技巧 1
- 漫谈索引
- UIButton常用属性和函数详解
- 大分辨率
- Android:Layout_weight的深刻理解
- excel根据列序号计算出对应的列字母
- Activity的创建和显示以及源码分析记录
- 正则表达式/^\w+$/i的理解
- LightOJ - 1042 Secret Origins (模拟)水
- Java提高篇之字符串的拼接
- GCD几种简单用法