UIButton的简单使用
2014-02-14 15:19
323 查看
UIButton
button.adjustsImageWhenDisabled = NO; //当设置按钮不可用时,按钮的颜色会变化,此属性来控制这个功能是否开启,设置为NO时,颜色不变
button.adjustsImageWhenHighlighted = NO; //当按钮处于高亮状态时,按钮颜色不变
reversesTitleShadowWhenHighlighted //当按钮处于高亮状态时,标题的阴影是否改变
showsTouchWhenHighlighted //点击按钮时是否让其发光
tintColor //提示的颜色
//设置按钮中的内容里四个边界的距离 四个参数分别代表的是距离上,左,下,右边界的距离,如果本身距边界距离大于参数,则布局不变
button.contentEdgeInsets = UIEdgeInsetsMake(0,10,
0,
0);
同上
imageEdgeInsets
titleEdgeInsets
//当前按钮的标题,只读方法
currentAttributedTitle
NSAttributedString *currentAttributedTitle
= button.currentAttributedTitle; //但是按钮的标题默认为空
currentBackgroundImage 当前按钮的背景,只读
UIImage image = button.currentBackgroundImage;
titleLabel 只读 显示currentTitle的视图
currentTitleShadowColor 只读
- (void)setAttributedTitle:(NSAttributedString *)title forState:(UIControlState)state
设置标题
- (void)setBackgroundImage:(UIImage *)image forState:(UIControlState)state
设置背景图片
-
(void)setImage:(UIImage *)image forState:(UIControlState)state
设置按钮图片
-
(void)setTitle:(NSString *)title forState:(UIControlState)state
设置标题
- (void)setTitleColor:(UIColor *)color forState:(UIControlState)state
设置标题字体
- (void)setTitleShadowColor:(UIColor *)color forState:(UIControlState)state
设置标题阴影
- (UIColor *)titleColorForState:(UIControlState)state
返回某个状态下提示的颜色
-
(NSString *)titleForState:(UIControlState)state
返回某个状态下的标题
-
(UIColor *)titleShadowColorForState:(UIControlState)state
返回某个状态下的标题阴影颜色
-
(CGRect)backgroundRectForBounds:(CGRect)bounds
返回控件的背景CGRect bound是接收着的CGRect
-
(CGRect)contentRectForBounds:(CGRect)bounds
返回内容的CGRect bound是接收着的CGRect
-
(CGRect)imageRectForContentRect:(CGRect)contentRect
返回控件的图片CGRect contentRect是内容的CGRect
添加点击事件
[button addTarget:self
action:@selector(btnClick:)
forControlEvents:UIControlEventTouchUpInside];
button.adjustsImageWhenDisabled = NO; //当设置按钮不可用时,按钮的颜色会变化,此属性来控制这个功能是否开启,设置为NO时,颜色不变
button.adjustsImageWhenHighlighted = NO; //当按钮处于高亮状态时,按钮颜色不变
reversesTitleShadowWhenHighlighted //当按钮处于高亮状态时,标题的阴影是否改变
showsTouchWhenHighlighted //点击按钮时是否让其发光
tintColor //提示的颜色
//设置按钮中的内容里四个边界的距离 四个参数分别代表的是距离上,左,下,右边界的距离,如果本身距边界距离大于参数,则布局不变
button.contentEdgeInsets = UIEdgeInsetsMake(0,10,
0,
0);
同上
imageEdgeInsets
titleEdgeInsets
//当前按钮的标题,只读方法
currentAttributedTitle
NSAttributedString *currentAttributedTitle
= button.currentAttributedTitle; //但是按钮的标题默认为空
currentBackgroundImage 当前按钮的背景,只读
UIImage image = button.currentBackgroundImage;
currentImage 当前按钮的图片,只读
currentTitle 当前标题,只读,反悔类型为NSString
currentTitleColor 只读
titleLabel 只读 显示currentTitle的视图currentTitleShadowColor 只读
METHOD
- (UIImage *)imageForState:(UIControlState)state
//返回某个状态下使用的图片
- (void)setAttributedTitle:(NSAttributedString *)title forState:(UIControlState)state设置标题
- (void)setBackgroundImage:(UIImage *)image forState:(UIControlState)state
设置背景图片
-
(void)setImage:(UIImage *)image forState:(UIControlState)state
设置按钮图片
-
(void)setTitle:(NSString *)title forState:(UIControlState)state
设置标题
- (void)setTitleColor:(UIColor *)color forState:(UIControlState)state
设置标题字体
- (void)setTitleShadowColor:(UIColor *)color forState:(UIControlState)state
设置标题阴影
- (UIColor *)titleColorForState:(UIControlState)state
返回某个状态下提示的颜色
-
(NSString *)titleForState:(UIControlState)state
返回某个状态下的标题
-
(UIColor *)titleShadowColorForState:(UIControlState)state
返回某个状态下的标题阴影颜色
-
(CGRect)backgroundRectForBounds:(CGRect)bounds
返回控件的背景CGRect bound是接收着的CGRect
-
(CGRect)contentRectForBounds:(CGRect)bounds
返回内容的CGRect bound是接收着的CGRect
-
(CGRect)imageRectForContentRect:(CGRect)contentRect
返回控件的图片CGRect contentRect是内容的CGRect
添加点击事件
[button addTarget:self
action:@selector(btnClick:)
forControlEvents:UIControlEventTouchUpInside];
相关文章推荐
- UIButton的简单使用
- 【swift系列之UIButton】简单使用
- 【iOS开发】简单UI部分UIButton的创建和UITextField的使用
- UILabel,UIButton,UITextField的简单使用
- swift中UIButton的简单使用
- UIButton的简单使用
- UIButton的简单使用
- UILabel、UITextField、UIButton简单使用
- 触发器的简单使用
- 华兴软通短信接口简单使用WebServices版
- JUnit 简单的使用 (学习转载)
- 使用C#创建简单的联系人备忘录
- CoreImage的一处简单使用
- iOS开发UI篇—使用xib自定义UItableviewcell实现一个简单的团购应用界面布局
- 简单使用handler.postDelayed()方法
- 【Linux运维入门】Linux环境安装配置MongoDb及简单使用
- 用CornerStone配置SVN,HTTP及svn简单使用说明
- BootStrap简单组件使用
- GitHub入门教程:(1)简单的git使用,同步仓库
- jarinjar的简单使用之打包第三方jar到一个可执行jar文件。