easier way to keep button in highlight mode after touch?

Discussion in 'iOS Programming' started by mikezang, Nov 4, 2010.

  1. mikezang macrumors 6502a

    Joined:
    May 22, 2010
    Location:
    Tokyo, Japan
    #1
    I use a NSTimer to set button in highlight mode after touch, is this a easier way and can be run on device?

    Code:
    -(IBAction) selectFourVoice:(id)sender {
    	UIButton *fourVoice = nil;
    	
    	for (int i = EvenTone; i <= 400; i+=100) {
    		fourVoice = (UIButton *)[self viewWithTag:i];
    		
    		fourVoice.enabled = YES;
    		fourVoice.highlighted = NO;
    	}
    	
    	fourVoice = (UIButton *)sender;
    	
    	for (int i = 1; i <= 4; i++) {
    		for (int j = 1 + 100 * i; j <= 100 * i + 10; j++) {
    			UIButton *key = (UIButton *)[self viewWithTag:j];
    			
    			[self setKeyTitle:key forTone:fourVoice.tag];
    		}
    	}
    
    	[NSTimer scheduledTimerWithTimeInterval:0.0 target:self selector:@selector(timerSetKeyHighlight:) userInfo:fourVoice repeats:NO];
    }
    
    -(void) timerSetKeyHighlight:(NSTimer *)timer {
    	UIButton *fourVoice = (UIButton *)[timer userInfo];
    	fourVoice.highlighted = YES;
    	fourVoice.enabled = NO;	
    }
    
     

    Attached Files:

  2. ritsard macrumors regular

    ritsard

    Joined:
    Jun 18, 2009
    Location:
    SF Bay Area, CA
    #2
    Just curious, why do you want to keep the button highlighted after the press?
     
  3. mikezang thread starter macrumors 6502a

    Joined:
    May 22, 2010
    Location:
    Tokyo, Japan
    #3
    Because the buttons of right are set of the most left buttons.
    For example, the top left button is "A", when it is touched, the right buttons will show "An", "Apple", and so on.
     

Share This Page