首页 > 其他 > 详细

纯代码创建Button控件:

时间:2015-03-12 00:50:36      阅读:289      评论:0      收藏:0      [点我收藏+]
纯代码创建Button控件:

// 创建按钮
UIButton *btn = [[UIButton alloc] init];

// 添加按钮
[self.view addSubview:btn];

// 设置frame
btn.frame = CGRectMake(50, 50, 100, 100);

// 设置背景图片
// 通过文件名加载图片(凡是PNG图片,都不用加拓展名)
UIImage *normal = [UIImage imageName:@“btn_01”];
// 设置普通状态下的背景图片
[btn setBackgroundImage:normal forState:UIControlStateNormal];

// 加载高亮的图片
UIImage *hight = [UIImage imageName:@“btn_02”];
[btn setBackgroundImage:normal forState:UIControlStateHighlighted];

// 设置文字
[btn setTitle:@“按钮1” forState:UIControlStateNormal];
[btn setTitle:@“按钮2” forState:UIControlStateHighlighted];

// 设置文字颜色
[btn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[btn setTitleColor:[UIColor blueColor] forState:UIControlStateHightlighted];

 

纯代码创建Button控件:

原文:http://www.cnblogs.com/pocket-mood/p/4331293.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!