IOS UIButton 代码创建
来源:互联网 发布:重庆时时开奖软件 编辑:程序博客网 时间:2024/05/20 06:22
// 创建按钮
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; //绘制形状
// 确定宽、高、X、Y坐标
CGRect frame;
frame.size.width = 100;
frame.size.height = 30;
frame.origin.x = 320 / 2 - 50;
frame.origin.y = 480 / 2 - 30;
[btn setFrame:frame];
// 设置Tag(整型)
btn.tag = 10;
// 设置标题
[btn setTitle:@"按钮" forState:UIControlStateNormal];
// 设置未按下和按下的图片切换
[btn setBackgroundImage:[UIImage imageNamed:@"bus.png"] forState:UIControlStateNormal];
[btn setBackgroundImage:[UIImage imageNamed:@"plane.png"] forState:UIControlStateHighlighted];
// 设置事件
[btn addTarget:self action:@selector(btnPressed:) forControlEvents:UIControlEventTouchUpInside];
// 设置背景色和透明度
[btn setBackgroundColor:[UIColor blackColor]];
[btn setAlpha:0.8];
// 或设置背景色和透明度
btn.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.8];
[self.view addSubview:btn];
//按钮响应事件
-(void)btnPressed:(id)sender
{
UIButton *myBtn = (UIButton *)sender;
if (myBtn.tag == 10)
{
// TODO:
}
}
- IOS -- UIButton 代码创建
- IOS UIButton 代码创建
- IOS---使用代码创建UIButton
- 【iOS开发】使用代码创建UIButton
- IOS 学习八 代码创建UIButton
- IOS UI 代码创建UIButton,UITextField,UILabel
- iOS UIButton创建
- IOS 代码控制UIButton
- UIButton--通过代码创建按钮
- iOS学习笔记 4 —— 代码创建界面UIView、UILabel、UITextField、UIButton
- swift代码创建控件之UIButton
- 用代码快速创建UIButton和UILabel
- IOS 代码总结 UIImage UILabel UIButton
- IOS UIButton的一些设置代码
- iOS开发系列之常用自定义控件开发集—继承UIButton控件代码快速创建按钮开发
- UIButton 创建
- 创建UIButton
- 创建UIButton
- 软件正交架构
- LInux内核启动
- 48. 搜狗面试题:从尾到头输出链表
- 展讯功能机平台抓log
- MySQL错误:You are using safe update mode and you tried to update a table without a WHERE that uses a K
- IOS UIButton 代码创建
- crash 调试kernel
- c++虚函数
- 浅谈-----包及访问权限(一)
- 一切为了您的阅读价值
- 初级UI设计中的颜色渐变
- MFC学习笔记(四)
- cordova搭建篇
- Java中synchronized关键字的简单理解