iOS之代码创建button

来源:互联网 发布:淘宝怎么避免虚假交易 编辑:程序博客网 时间:2024/05/17 22:47

在storyBoard连线的时候,方法返回值是IBAction,所谓IBAction就是可以连线的void


    UIButton *button = [UIButtonbuttonWithType:UIButtonTypeCustom];

    

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

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

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

    

    [button setTitleColor:[UIColorredColor] forState:UIControlStateNormal];

    [button setTitleColor:[UIColorgreenColor] forState:UIControlStateHighlighted];

    

    [button setBackgroundColor:[UIColororangeColor]];

     //点击执行的函数

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

    

    [self.viewaddSubview:button];



0 0
原创粉丝点击