How do I create a basic UIButton programmatically?

后端 未结 30 1201
清歌不尽
清歌不尽 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 *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [button addTarget:self 
               action:@selector(aMethod:)
     forControlEvents:UIControlEventTouchUpInside];
    [button setTitle:@"Show View" forState:UIControlStateNormal];
    button.frame = CGRectMake(10.0, 100.0, 300.0, 20.0);
    [self.view addSubview:button];
    

提交回复
热议问题