UI 总结-1 UIButton

//---------------------UIButton---------------------
// 1 创建
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

//*********创建圆角button
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];

button1.frame = CGRectMake(50, 50, 100, 80);
button.center = CGPointMake(180, 215);
button.tag = 100;
button1.backgroundColor = [UIColor whiteColor];


// 2 设置文字
[button1 setTitle:@"点我" forState:UIControlStateNormal];
[button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];

//********定义按钮标题字体格式
[button.titleLabel setFont:[UIFont boldSystemFontOfSize:20]];
button.titleLabel.textAlignment = NSTextAlignmentCenter;
// button.titleLabel.font

// 3 添加点击事件
/**
* UIControlEventTouchDown 按钮被按下
* UIControlEventTouchDownRepeat 多次按下
* UIControlEventTouchDragInside 拖拽到按钮内部放开
* UIControlEventTouchDragOutside 拖拽到按钮外部放开
* UIControlEventTouchDragEnter 从按钮外部拖入到内部的过程
* UIControlEventTouchDragExit 从按钮内部拖入到外部的过程
* UIControlEventTouchUpInside 按钮被按下,并且在按钮内部放开
* UIControlEventTouchUpOutside 按钮被按下,并且在按钮外部放开
* UIControlEventTouchCancel 点击被取消 电话中断按钮
*
*/

[button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:button];
[self.view addSubview:button1];

//---------------------使用图片设置按钮---------------------
UIButton *imgButton = [UIButton buttonWithType:UIButtonTypeCustom];
imgButton.frame = CGRectMake(50, 250, 90, 44);

// 设置按钮的图片
// imageNamed: 从当前程序的资源文件夹中读取图片 png图片,可以省略扩展名,其他格式不行
UIImage *image = [UIImage imageNamed:@"back_on_black"];
// 设置普通状态下的图片
//[imgButton setImage:image forState:UIControlStateNormal];
// 设置高亮状态下的图片 当手指触摸到按钮时,按钮自动进入到高亮状态
//[imgButton setImage:[UIImage imageNamed:@"back_on"] forState:UIControlStateHighlighted];

[imgButton setBackgroundImage:image forState:UIControlStateNormal];
[imgButton setBackgroundImage:[UIImage imageNamed:@"back_on"] forState:UIControlStateHighlighted];

// 设置title
[imgButton setTitle:@"返回" forState:UIControlStateNormal];
[imgButton setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];



// 按钮的开启和关闭
imgButton.enabled = YES;
// 开启点击效果 点击高亮
imgButton.showsTouchWhenHighlighted = YES;

// 选中
imgButton.selected = YES;

self.view.backgroundColor = [UIColor blackColor];
[self.view addSubview:imgButton];
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值