How do I create a basic UIButton programmatically?

后端 未结 30 914
清歌不尽
清歌不尽 2020-11-22 14:41

How can I create a basic UIButton programmatically? For example in my view controller, when executing the viewDidLoad method, three UIButton<

30条回答
  •  花落未央
    2020-11-22 15:31

    UIButton *custombutton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [custombutton addTarget:self
                     action:@selector(aMethod:)
           forControlEvents:UIControlEventTouchUpInside];
    [custombutton setTitle:@"Click" forState:UIControlStateNormal];
    custombutton.frame = CGRectMake(80.0, 110.0, 160.0, 40.0);
    custombutton.titleLabel.textColor = [UIColor colorWithRed: 2.0f/255.0f green: 155.0f/255.0f blue: 213.0f/255.0f  alpha:1];
     [custombutton setImage:[UIImage imageNamed:@"hh.png"] forState:UIControlStateNormal];
     [view addSubview:custombutton];
    

提交回复
热议问题