Dies ist auch ein Beispiel für die Erstellung von drei Schaltflächen. Verschieben Sie einfach ihre Position.
UIImage *buttonOff = [UIImage imageNamed:@"crysBallNorm.png"];
UIImage *buttonOn = [UIImage imageNamed:@"crysBallHigh.png"];
UIButton *predictButton = [UIButton alloc];
predictButton = [UIButton buttonWithType:UIButtonTypeCustom];
predictButton.frame = CGRectMake(180.0, 510.0, 120.0, 30.0);
[predictButton setBackgroundImage:buttonOff forState:UIControlStateNormal];
[predictButton setBackgroundImage:buttonOn forState:UIControlStateHighlighted];
[predictButton setTitle:@"Predict" forState:UIControlStateNormal];
[predictButton setTitleColor:[UIColor purpleColor] forState:UIControlStateNormal];
[predictButton addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:predictButton];
0 Stimmen
webindream.com/einfuegen-uibutton-programmatisch-in-swift hat ein gutes Tutorial, um uibutton programmatisch hinzuzufügen
0 Stimmen
UIButton in Swift erstellen, stackoverflow.com/questions/24102191/