7
A
回答
1
要更改按钮底色图像或文本对于这个问题 - 你需要改变它的特定UIControlState ...即突出显示,选择,残疾人
使用
- (void)setBackgroundImage:(UIImage *)image forState:(UIControlState)state
我不知道你是否能它们的动画,我从来没有尝试过。如果你不能为它们设置动画,那么你可以把UIImageView放在一个透明的按钮后面,然后将图像制作成动画 - 只是一个想法。
0
是的,这是可能的。使用NSTimer,
NSTimer * myTimer = [NSTimer scheduledTimerWithTimeInterval:5.00 target:self selector:@selector(changeImage)userInfo:nil repeatats:YES];
然后,方法如下,
- (void)changeImage
{
static int counter = 0;
if([bannerArray count] == counter)
{
counter = 0;
}
[button setImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:bannerArray[counter]]]] forState:UIControlStateNormal];
counter++;
}
它为我工作。但添加像翻转等动画需要弄清楚。希望这也是一种方法来帮助你的需要。
1
您可以动画的UIButton
你的动画UIImageView
这样的方式......
-(void) addAnimationToButton:(UIButton*) button{
UIImageView* animationView = [button imageView];
NSArray* animations=[NSArray arrayWithObjects:
[UIImage imageNamed:@"sprite1.png"],
[UIImage imageNamed:@"sprite2.png"],
[UIImage imageNamed:@"sprite2.png"],
//and so on if you need more
nil];
CGFloat animationDuration = 2.0;
[animationView setAnimationImages:animations];
[animationView setAnimationDuration:animationDuration];
[animationView setAnimationRepeatCount:0]; //0 is infinite
}
并且你使用这样的:
[self addAnimationToButton:yourButton];
[[yourButton imageView] startAnimating]; //or stopAnimating
11
这里就是我所做的(一个UIButton子类中, ):
设置按钮图像,像常规:
[self setBackgroundImage:[[UIImage imageNamed:@"button"] resizableImageWithCapInsets:UIEdgeInsetsMake(10.0, 10.0, 10.0, 10.0)] forState:UIControlStateNormal];
[self setBackgroundImage:[[UIImage imageNamed:@"button_pressed"] resizableImageWithCapInsets:UIEdgeInsetsMake(10.0, 10.0, 10.0, 10.0)] forState:UIControlStateHighlighted];
改写强调:
- (void)setHighlighted:(BOOL)highlighted {
[UIView transitionWithView:self duration:0.25 options:UIViewAnimationOptionTransitionCrossDissolve | UIViewAnimationOptionAllowAnimatedContent animations:^{
[super setHighlighted:highlighted];
} completion:nil];
}
+0
这是一个绝妙的解决方案 – 2015-08-13 00:03:05
相关问题
- 1. 背景动画图像
- 2. 背景图像动画
- 3. jQuery背景图像动画
- 4. CSS背景图像动画
- 5. UIButton背景图像不变
- 6. UIButton的图像和背景
- 7. UIButton图像/背景图像古怪
- 8. 图像和背景图像的UIButton
- 9. 像启动画面的背景图像
- 10. 动画自动更改背景图像
- 11. CSS背景图像滚动动画
- 12. 如何动画UIButton背景色
- 13. jQuery从CSS动画背景图像
- 14. 恒星动画背景图像效果
- 15. CSS3 - 动画背景图像过滤器
- 16. 动画虚线SVG的背景图像
- 17. 动画从图像中填充背景
- 18. 如何动画背景图像转换?
- 19. jquery动画背景图像转换
- 20. jQuery背景图像“淡入”动画
- 21. 动画背景图像:后元件
- 22. 动画布局背景图像变化
- 23. Css背景图像位置动画
- 24. 动画背景图像相对于mousemove
- 25. wpf动态画布背景图像
- 26. WP8中的动画背景图像
- 27. 大图像背景的Ch啪动画
- 28. JS动画的背景图像缩放
- 29. 背景图像动画在Firefox
- 30. 用动画加载背景图像
我已经把一个UIImageView后面的透明按钮。有点不好意思,但我可以说什么 - 这工作! 10x – Rizon 2012-01-17 15:47:48