A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© holmesconan 中级黑马   /  2015-12-28 00:13  /  702 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

UIButton的初始化

UIButton *batton = [UIBtton buttonWithType:UIButtonTypeRoundedRect];// 便利构造器

button.frame = CGRectMake(100,10,100,100);

[button setTitle:@“按钮” forState:UIControStateNormal];

[button addTarget:self action:@selector(changeTitle:触发事件)forControlEcents:UIControlEventTouchUpInside触发方式];




UIControlEventTouchUpInside;//触摸弹起事件
UIControlValueChange;//值变化事件
UIControlTouchDown//边界内触摸按下事件
UIContorlTouchDownRepeat//轻击数大于1的重复按下事件


- (void)changeTitle:(id)sender
{
    UIButton *button = (uibutton *)Sender;//强制类型转换
    [button settitle:@“按钮点击”fortate:uicontrolstatenormal];
}


设置背景和文字
正常状态下
[batton setBackroundImage:[UIImage imageNamed:@“1.png”]forState:UIControlStateNormal]
title方法与背景图
[button setTitle:@“按钮”forState :UIcontrolStateNormal];
高亮状态下
[batton setBackroundImage:[UIImage imageNamed:@“1.png”]forState:UIControlStateHighlighted];


UIcontrlStateSelected//选中状态
UIcontrlStateDisabled//无法交互状态

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马