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;
}
}
补充:移动开发 , IOS ,