我正在尝试循环四个亮度稍高的图像,我试图让它看起来像是在发光,但是我认为代码并没有像我想象的那样工作
-(void)loadRefreshButton{
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
refreshButton = button;
[button addTarget:self
action:@selector(refreshButtonPressedResult)
forControlEvents:UIControlEventTouchDown]; [refreshButton setTitle:@"" forState:UIControlStateNormal];
refreshButton.frame = CGRectMake(80.0, 370.0, 76, 76);
[self.view addSubview:refreshButton];
NSTimer* timer = [NSTimer scheduledTimerWithTimeInterval: 1.0
target: self
selector: @selector(toggleButtonImage:)
userInfo: nil
repeats: YES];
}
- (void)toggleButtonImage:(NSTimer*)timer
{
if(toggle)
{
[refreshButton setImage:[UIImage imageNamed:@"button_zero.png"] forState: UIControlStateNormal];
[refreshButton setImage:[UIImage imageNamed:@"button_one.png"] forState: UIControlStateNormal];
[refreshButton setImage:[UIImage imageNamed:@"button_two.png"] forState: UIControlStateNormal];
[refreshButton setImage:[UIImage imageNamed:@"button_three.png"] forState: UIControlStateNormal];
}
else
{
[refreshButton setImage:[UIImage imageNamed:@"button_three.png"] forState: UIControlStateNormal];
[refreshButton setImage:[UIImage imageNamed:@"button_two.png"] forState: UIControlStateNormal];
[refreshButton setImage:[UIImage imageNamed:@"button_one.png"] forState: UIControlStateNormal];
[refreshButton setImage:[UIImage imageNamed:@"button_zero.png"] forState: UIControlStateNormal];
}
toggle = !toggle;
}
谢谢!