Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have imageview in which I am adding UIButton it shows button when I click on button it does not call the action of the button. Here is the code I am using I have also set the imageView.userInteraction=enabled but still it is not calling the action.

UIImageView*myImageView=[[UIImageView alloc] initWithFrame:CGRectMake(75,10,200,150)];


myImageView.image=thumbnail;

myImageView.userInteractionEnabled=YES;


[scrollView addSubview:myImageView];

UIButton*playButton=[[UIButton alloc] initWithFrame:CGRectMake(20,20,128,128)];

//[playButton setImage:[UIImage imageNamed:@"playIconPlay.png"] forState:UIControlStateNormal];

[playButton.buttonType:UIButtonTypeRoundedRect];

scrollView.userInteractionEnabled=YES;
myImageView.userInteractionEnabled=YES;
[playButton setTitle:@"Play Click" forState:UIControlStateNormal];

[playButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];


[playButton addTarget:self action:@selector(playButtonAction) forControlEvents:UIControlEventTouchUpInside];


myImageView.userInteractionEnabled=YES;

[myImageView addSubview:playButton];
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
150 views
Welcome To Ask or Share your Answers For Others

1 Answer

you can add a UIImageView and and UIButton in a UIView, hope it will help for you.

UIView* view = [[UIView alloc] initWithFrame:CGRectMake(75, 10, 200, 150)];

UIImageView*myImageView=[[UIImageView alloc] initWithFrame:CGRectMake(0,0,200,150)];


myImageView.image=thumbnail;


[view addSubview:myImageView];

[scrollView addSubview:view];

UIButton*playButton=[[UIButton alloc] initWithFrame:CGRectMake(20,20,128,128)];

//[playButton setImage:[UIImage imageNamed:@"playIconPlay.png"] forState:UIControlStateNormal];

[playButton.buttonType:UIButtonTypeRoundedRect];

[playButton setTitle:@"Play Click" forState:UIControlStateNormal];

[playButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];


[playButton addTarget:self action:@selector(playButtonAction) forControlEvents:UIControlEventTouchUpInside];


myImageView.userInteractionEnabled=YES;

[view addSubview:playButton];

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...