你好,歡迎來到IOS教程網

 Ios教程網 >> IOS訊息 >> 關於IOS >> iOS 之點擊按鈕改變狀態的圖片

iOS 之點擊按鈕改變狀態的圖片

編輯:關於IOS

.h  文件中

  @property (strong, nonatomic) IBOutlet UIButton *publishBtton;   @property (strong, nonatomic) IBOutlet UIButton *timeLineButton;   @property (strong, nonatomic) IBOutlet UIButton *chatButton;   @property (strong, nonatomic) IBOutlet UIButton *topicButton;       .m 文件中         - (void)viewDidLoad   {       [super viewDidLoad];              _buttonArray=@[_publishBtton,_timeLineButton,_chatButton,_topicButton];              [_publishBtton setImage:[UIImage imageNamed:@"publish"] forState:UIControlStateNormal];       [_timeLineButton setImage:[UIImage imageNamed:@"timeLineAfter"] forState:UIControlStateNormal];       [_chatButton setImage:[UIImage imageNamed:@"chatBefore"] forState:UIControlStateNormal];       [_chatButton setImage:[UIImage imageNamed:@"chatAfter"] forState:UIControlStateSelected];       [_topicButton setImage:[UIImage imageNamed:@"topicBefore"] forState:UIControlStateNormal];       [_topicButton setImage:[UIImage imageNamed:@"topicAfter"] forState:UIControlStateSelected];          }       -(void)changeButtonState:(UIButton *)button buttons:(NSArray *)buttonArray   {       for (UIButton* b in buttonArray)       {           b.selected=NO;       }          button.selected=YES;   }       //點擊按鈕事件   - (IBAction)changeView:(UIButton *)sender   {              [self changeButtonState:sender buttons:_buttonArray];       switch (sender.tag) {           case 400:           {                [_timeLineButton setImage:[UIImage imageNamed:@"timeLineBefore"] forState:UIControlStateNormal];               break;           }           case 401:           {               [_timeLineButton setImage:[UIImage imageNamed:@"timeLineAfter"] forState:UIControlStateSelected];               break;           }           case 402:           {             [_timeLineButton setImage:[UIImage imageNamed:@"timeLineBefore"] forState:UIControlStateNormal];               break;           }           case 403:           {              [_timeLineButton setImage:[UIImage imageNamed:@"timeLineBefore"] forState:UIControlStateNormal];                    break;           }             default:               break;       }          }
  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved