iOS入门之UI03 --UIButton

/**

*UIButton 按钮 触发点击事件

*继承自UIVIew,大小,边框,背景色设置相同

*/

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

/**

* UIButtonTypeCustom = 0, //自定义(常加载图片) no button type

* UIButtonTypeRoundedRect, //圆角按钮

* UIButtonTypeDetailDisclosure, //尖叫号按钮

* UIButtonTypeInfoLight, 信息按钮(浅)

* UIButtonTypeInfoDark, 信息按钮(深)

* UIButtonTypeContactAdd, 加号按钮

*/

/**button存在4种状态

*1⃣️normal:默认为通常状态下

*2⃣️selected:选中状态(自己设定)

*3⃣️hightLight:高亮状态(normal状态下点击不放开)

*4⃣️disabled:不可编辑状态(自己设定)

*/

//设置button上的文字

/* 1 (可访问button上的lable,对button上的字体进行设置)*/

button.titleLabel.text = @"hello world";

/* 2 */

[button setTitle:@"点我" forState:UIControlStateNormal];

[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

// 设置button图片,具体细节自己观察

[button setImage:[UIImage imageNamed:@"图片名"] forState:UIControlStateNormal];

// 设置button背景图片,具体细节自己观察

[button setBackgroundImage:connectButtonBackgroundImage forState:UIControlStateNormal];

/* 设置对齐方式

*/

button.contentVerticalAlignment = UIControlContentVerticalAlignmentBottom;

/**taget-action机制

*参数1:控件(button)

*参数2:发送消息的对象(self)

*参数3:发送消息,即执行的响应事件(onButtonClick:)

*参数4:发送消息的触发条件

*/

[button addTarget:self action:@selector(onButtonClick:) forControlEvents:UIControlEventTouchDown];

}

-(void)onButtonClick:(UIButton *)sender{

NSLog(@"点击事件");

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 一个UIButton的实例变量, 使一个按钮(button)在触摸屏上生效。一个按钮监听触摸事件,当被点击时,给目...
    wushuputi阅读 1,560评论 0 1
  • iOS开发系列--网络开发 概览 大部分应用程序都或多或少会牵扯到网络开发,例如说新浪微博、微信等,这些应用本身可...
    lichengjin阅读 3,735评论 2 7
  • 前言:UI控件整理之UIButton 一、显示图片(复选框) UIButton *button = [UIButt...
    心如止水的鱼阅读 304评论 0 0
  • 1.transform属性 在OC中,通过transform属性可以修改对象的平移、缩放比例和旋转角度 常用的创建...
    SacredBillows阅读 1,386评论 0 0
  • 文:耳双生 4月1日,千里迢迢来听歌神的演唱会。 他说,这是他的第65场,也是室外的第4场。也是室外场中,天气最棒...
    耳双生阅读 368评论 1 4