Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 以编程方式将按钮放置在图像上_Ios_Image_Button - Fatal编程技术网

Ios 以编程方式将按钮放置在图像上

Ios 以编程方式将按钮放置在图像上,ios,image,button,Ios,Image,Button,我把这个编码了: UIButton *buttonPrint = [UIButton buttonWithType:UIButtonTypeCustom]; [buttonPrint setImage:[UIImage imageNamed:@"stampa.png"] forState:UIControlStateNormal]; buttonPrint.frame = CGRectMake(15, 5, 117, 41); [buttonPrint addTarget:self action

我把这个编码了:

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

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

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

希望能有帮助。干杯