Note that there are some explanatory texts on larger screens.

plurals
  1. POChange UIButton image upon another button selection
    primarykey
    data
    text
    <p>I have 2 buttons in my UIView underneath a video,a play and a stop button.When Play button is clicked,it turns out to pause button and vice-versa.Here is the implementation code:</p> <pre><code>-(UIView *)subViewControlsView{ UIView *subViewWithControls = [[[UIView alloc]init]autorelease]; subViewWithControls = [[UIView alloc]initWithFrame:CGRectMake((self.view.frame.size.width - xPoint_Pad) - 147, 630, 147, 44)]; [subViewWithControls setBackgroundColor:[UIColor clearColor]]; playButton = [UIButton buttonWithType:UIButtonTypeCustom]; [playButton setFrame:CGRectMake(0, 0, 44, 44)]; [playButton setImage:[UIImage imageNamed:@"play.png"] forState:UIControlStateNormal]; [playButton setImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateSelected]; [playButton addTarget:self action:@selector(play:) forControlEvents:UIControlEventTouchUpInside]; [subViewWithControls addSubview:playButton]; stopButton = [UIButton buttonWithType:UIButtonTypeCustom]; [stopButton setFrame:CGRectMake(94, 0, 44, 44)]; [stopButton setImage:[UIImage imageNamed:@"stop.png"] forState:UIControlStateNormal]; [stopButton addTarget:self action:@selector(stop:) forControlEvents:UIControlEventTouchUpInside]; [subViewWithControls addSubview:stopButton]; return subViewWithControls; } </code></pre> <p>and here is the play button action:</p> <pre><code>-(void)play:(UIButton *)sender { if(sender.selected == NO){ sender.selected = YES; [self setButtonCurrentState:YES]; [self.moviePlayerController setInitialPlaybackTime:self.currentTime]; [self playMovieFile:[self localMovieURL]]; } else{ sender.selected = NO; [self setButtonCurrentState:NO]; self.currentTime = self.moviePlayerController.currentPlaybackTime; [self.moviePlayerController pause]; } } </code></pre> <p>My requirement is I need to change the play image to pause for play button once the video is stopped i.e. when user clicks stop button.I have tried the below way:</p> <pre><code>-(void)stop:(UIButton *)sender{ if (self.buttonCurrentState == YES) { [playButton setImage:[UIImage imageNamed:@"play.png"] forState:UIControlStateNormal]; } self.currentTime = 0.0; [[self moviePlayerController] stop]; [self deletePlayerAndNotificationObservers]; } </code></pre> <p>It is validating the condition in stop button action,I have already debugged and tested,but the image change doesn't affect.Wonder the reason why??</p> <p>I have also tried changing the images in play button action instead of doing in <code>-(UIView *)subViewControlsView</code> method.But what happens is to my surprise,I can't see the button as the image is not set in the view method.I have tried to set up the image as play initially for control state normal and then change in play action.Now what happens is the play button doesn't turn to pause button,which is a double blow.I tried setting tags,boolean values and lot more.None of them seem to work!!!</p> <p>Can any one please suggest me a solution?</p> <p>Thanks all in advance :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload