I coded this:
UIButton *buttonPrint = [UIButton buttonWithType:UIButtonTypeCustom];
[buttonPrint setImage:[UIImage imageNamed:@"stampa.png"] forState:UIControlStateNormal];
buttonPrint.frame = CGRectMake(15, 5, 117, 41);
[buttonPrint addTarget:self action:@selector(print) forControlEvents:UIControlEventTouchUpInside];
[viewBack addSubview:buttonPrint];
//button mail
UIButton *buttonMail = [UIButton buttonWithType:UIButtonTypeCustom];
[buttonMail setImage:[UIImage imageNamed:@"mail.png"] forState:UIControlStateNormal];
buttonMail.frame = CGRectMake(0, 46, 117, 41);
[buttonMail addTarget:self action:@selector(sendEmail) forControlEvents:UIControlEventTouchUpInside];
[viewBack addSubview:buttonMail];
//button facebook
UIButton *buttonPublish = [UIButton buttonWithType:UIButtonTypeCustom];
[buttonPublish setImage:[UIImage imageNamed:@"pubblica.png"] forState:UIControlStateNormal];
buttonPublish.frame = CGRectMake(20, 90, 117, 41);
[buttonPublish addTarget:self action:@selector(publish) forControlEvents:UIControlEventTouchUpInside];
[viewBack addSubview:buttonPublish];
//button twitter
UIButton *buttonTweet = [UIButton buttonWithType:UIButtonTypeCustom];
[buttonTweet setImage:[UIImage imageNamed:@"tweet.png"] forState:UIControlStateNormal];
buttonTweet.frame = CGRectMake(4, 130, 117, 41);
[buttonTweet addTarget:self action:@selector(tweet) forControlEvents:UIControlEventTouchUpInside];
[viewBack addSubview:buttonTweet];
- (void)sendEmail {
NSLog(@"mail clicked");
}
- (void)tweet {
NSLog(@"tweetClicked");
}
- (void)print {
NSLog(@"printClicked");
}
- (void)publish {
NSLog(@"face clicked");
}
but the buttons does not work… What should i do??
UIImageViewhas a propertyuserInteractionEnabled. It’s disabled by the default, so if you are adding youre buttons as a subviews of the image view they will not respond. If this is your issue. you can enable that flag or consider to move the buttons to the image view’s superview.Hope it helps. Cheers.