2011-05-09 72 views

回答

2

沒有內置的方式,但我能想到的幾種方法(根據您的需要):

  • 綁定按鈕是切換無論方法按鈕是爲了切換,然後相應地改變按鈕的image財產
  • 創建您自己的UIBarButtonItem子類,它看起來是這樣的:

    @interface ToggleBarButtonItem : UIBarButtonItem { 
        BOOL _state; 
        UIImage * onImage; 
        UIImage * offImage; 
    } 
    - (BOOL)toggleState; 
    @property (nonatomic, retain) UIImage * onImage; 
    @property (nonatomic, retain) UIImage * offImage; 
    @end 
    
    @implementation ToggleBarButtonItem 
    - (BOOL)toggleState { 
        if (_state) { 
         // Switch to Off state 
         self.image = offImage; 
        } 
        else { 
         // Switch to On state 
         self.image = onImage; 
        } 
        return _state = !_state; 
    } 
    @end