In iOS, can a UIButton be added by alloc and initWithFrame?
问题 A button can be added by: UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; myButton.frame = CGRectMake(100, 100, 160, 50); [myButton setTitle:@"click me" forState:UIControlStateNormal]; [self.view addSubview:myButton]; but can we go with the initWithFrame method: UIButton *myButton2 = [[UIButton alloc] initWithFrame:CGRectMake(100, 300, 160, 50)]; //myButton2.buttonType = UIButtonTypeRoundedRect; myButton2.titleLabel.text = @"click me"; [self.view addSubview:myButton2];