UIButton各种属性

//这里创建一个圆角矩形的按钮

UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];

//能够定义的button类型有以下6种

//typedef enum {

//UIButtonTypeCustom = 0,   自定义风格

//UIButtonTypeRoundedRect,   圆角矩形

//UIButtonTypeDetailDisclosure,   蓝色小箭头按钮,主要做详细说明用

//UIButtonTypeInfoLight,   亮色感叹号

//UIButtonTypeInfoDark,   暗色感叹号

//UIButtonTypeContactAdd,   十字加号按钮

//} UIButtonType;

//给定button在view上的位置

button1.frame = CGRectMake(20, 20, 280, 20);

//button背景色

button1.backgroundColor = [UIColor clearColor];

//设置button填充图片

button1 setImage:[UIImage imageName:@"btng.png"] forState:UIControlStateNormal];

//设置button标题

[button1 setTitle:@"点击" forState:UIControlStateNormal];

//forState: 这个参数的作用是定义按钮的文字或图片在何种状态下才会显现

//以下是几种状态

//enum {

//UIControlStateNormal = 0,   常规状态显现            

//UIControlStateHighlighted  = 1 << 0,   高亮状态显现  

//UIControlStateDisabled = 1 << 1,   禁用的状态才会显现

//UIControlStateSelected = 1 << 2,   选中状态            

//UIControlStateApplication = 0x00FF0000,   当应用程序标志时          

//UIControlStateReserved = 0xFF000000   为内部框架预留,可以不管他           

//};

//默认情况下,当按钮高亮的情况下,图像的颜色会被画深一点,如果这下面的这个属性设置为no,那么可以去掉这个功能

button1.adjustsImageWhenHighlighted = NO;

//跟上面的情况一样,默认情况下,当按钮禁用的时候,图像会被画得深一点,设置NO可以取消设置

button1.adjustsImageWhenDisabled = NO;

//下面的这个属性设置为yes的状态下,按钮按下会发光

button1.showsTouchWhenHighlighted = YES;

/* 给button添加事件,事件有很多种,我会单独开一篇博文介绍它们,下面这个时间的意思是按下按钮,并且手指离开屏幕的时候触发这个事件,跟web中的click事件一样。触发了这个事件以后,执行butClick:这个方法,addTarget:self 的意思是说,这个方法在本类中也可以传入其他类的指针*/

[button1 addTarget:self action:@selector(butClick:) forControlEvents:UIControlEventTouchUpInside];

//显示控件

[self.view addSubview:button1];

时间: 2024-08-10 21:22:46

UIButton各种属性的相关文章

0821基础控件(UIButton常用属性)

一.可以通过代码的方式创建UIButton 1.通用实例化对象方法: UIButton *button = [[UIButton alloc] initWithFrame:rect]; 2.快速实例化对象方法: UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 提示: 在OC开发中,实例化任何类型的非自定义对象,都请首先尝试一下是否存在快速定义方法.如果存在快速定义方法,就尽量不要使用init之类的方法实例

简述UIButton的属性和用法

UIButton属性 1.UIButton状态: UIControlStateNormal          // 正常状态    UIControlStateHighlighted     // 高亮状态    UIControlStateDisabled        // 禁用状态     UIControlStateSelected        // 选中状态     UIControlStateApplication     //      UIControlStateReserve

UIButton的属性和使用

UIButton的使用 1.创建和显示 文本按钮 UIButtonTypeSystem 图片按钮 UIButtonTypeCustom 系统预定义的按钮 UIButtonTypeContactAdd +号 UIButtonTypeInfoLight  i符号 注意: 按钮创建一般使用buttonWithType UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem]; button.frame = CGRectMake(10

UIButton常见属性和方法

一.创建,两种方法: 1. 常规的 initWithFrame UIButton *btn1 = [[UIButton alloc]initWithFrame:CGRectMake(10, 10, 80, 44)]; 2. UIButton 的一个类方法(也可以说是静态方法)buttonWithType UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 风格有如下: typedef enum { UIButto

【iOS开发-8】UIButton类型属性简单归纳以及自定义按钮的设置

(1)UIButton类继承自UIControl,而UIControl继承自UIView,因为UIView就是个矩形区域,所以UIButton实例化的对象其实都是一个矩形,虽然有各种圆角.增加联系人.信息按钮等等,给它们加个背景它们就现形成矩形了,而且它们有个frame属性,这就是设置位置和矩形框的. (2)UIButton创建一个按钮不用实例化,也就是不用alloc和init,而是直接调用内置的几个工厂方法即可,这一点和UILabel *label1=[[UILabel alloc]init]

IOS UIButton常用属性

//1.添加按钮 UIButton *nameView=[UIButton buttonWithType:UIButtonTypeCustom]; //nameView.backgroundColor=[UIColor redColor]; [nameView setBackgroundImage:[UIImage imageNamed:@"buddy_header_bg"] forState:UIControlStateNormal]; [nameView setBackground

iOS UIButton各类属性设置大全

//设置自定义的按钮 //UIButton *button1=[UIButton buttonWithType:UIButtonTypeCustom]; //设置一个圆角的按钮 UIButton *button1=[UIButton buttonWithType:UIButtonTypeRoundedRect]; button1.frame=CGRectMake(80,250,250, 30);//按钮的位置坐标 [button1 setTitle:@"Button1" forStat

UIButton控件属性

UIButton控件属性: 1.UIButton状态: UIControlStateNormal // 正常状态 UIControlStateHighlighted // 高亮状态 UIControlStateDisabled // 禁用状态 UIControlStateSelected // 选中状态 UIControlStateApplication // 应用状态 UIControlStateReserved // 保留状态 2.Uibutton类型: UIButtonTypeCustom

UIButton属性

UIButton属性 1.UIButton状态: UIControlStateNormal          // 正常状态 UIControlStateHighlighted     // 高亮状态 UIControlStateDisabled        // 禁用状态 UIControlStateSelected        // 选中状态 UIControlStateApplication     // UIControlStateReserved        // 保留状态 2.