黑马程序员技术交流社区

标题: uibutton [打印本页]

作者: holmesconan    时间: 2015-12-28 00:13
标题: uibutton
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//无法交互状态






欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2