您的位置:首页 > 移动开发 > IOS开发

iOS之代码创建button

2015-10-21 21:37 344 查看
在storyBoard连线的时候,方法返回值是IBAction,所谓IBAction就是可以连线的void

    UIButton *button = [UIButton
buttonWithType:UIButtonTypeCustom];

    

    [button setFrame:CGRectMake(110.0,
220.0, 100.0,
40.0)];

    [button setTitle:@"button默认状态"
forState:UIControlStateNormal];

    [button setTitle:@"button点击状态"
forState:UIControlStateHighlighted];

    

    [button setTitleColor:[UIColor
redColor] forState:UIControlStateNormal];

    [button setTitleColor:[UIColor
greenColor] forState:UIControlStateHighlighted];

    

    [button setBackgroundColor:[UIColor
orangeColor]];

     //点击执行的函数

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

    

    [self.view
addSubview:button];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: