1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
// création d'un bouton
UIButton *button= [UIButton buttonWithType:UIButtonTypeRoundedRect];
// taille et position relative à la fenêtre dans laquelle tu le créer
button.frame = CGRectMake(positionX, positionY, tailleX, tailleY);
// ajout d'un evenement
[button addTarget:self action:@selector(buttonTaped:) forControlEvents:UIControlEventTouchDown];
// une image ou un texte dans le boutton
//[button setBackgroundImage:[UIImage imageNamed:@"MonImage"] forState:UIControlStateNormal];
//[button setTitle:@"push me"];
// ajout dans la vue principale de ton écran
[self.view addSubview:button];
// récupération de l'event
-(void)buttonTaped:(UIButton *)buttonPressed
{
NSLog(@"hello word");
} |
Partager