0

我编码了这个:

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");
}

但按钮不起作用......我该怎么办?

4

1 回答 1

2

UIImageView有财产userInteractionEnabled。默认情况下它是禁用的,因此如果您将按钮添加为图像视图的子视图,它们将不会响应。如果这是你的问题。您可以启用该标志或考虑将按钮移动到图像视图的超级视图。

希望能帮助到你。干杯。

于 2012-09-24T14:59:41.543 回答