ios - 在 iOS 中 x 秒后从 UIButton 更改 UIImage

标签 ios iphone objective-c uibutton uiimage

我正在尝试在 1 秒后从 uibutton 更改 uiimage。我试着让线程休眠

[button1 setImage:[UIImage imageNamed:@"sameThing.png"] forState:UIControlStateNormal];

[NSThread sleepForTimeInterval:1]; 

[button1 setImage:[UIImage imageNamed:@"interrogation.png"] forState:UIControlStateNormal];

但是图像没有变化,Thread正常执行 感谢您的建议

最佳答案

试试这个

[self performSelector:@selector(updateBtnImage:)
           withObject: someObject       
           afterDelay:1];



-(void) updateBtnImage: (id) obj
{    
         //Set image here
         //If still not updating image here dispatch block on main thread manually like this 
            dispatch_async(dispatch_get_main_queue(), 
             ^{
             //Set image in this block 
              });

}

关于ios - 在 iOS 中 x 秒后从 UIButton 更改 UIImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20639347/

相关文章:

ios - Swift 中是否有仅在第一次打开应用程序时运行的功能?

iphone - iOS 中的测试驱动开发......是否采用 TDD

ios - 如何在 Facebook 中分享来自 IOS 应用程序的产品详细信息

ios - swift - 从 var(UITextField input) 中删除空格不起作用

iPhone+在评级时突出显示星级

iphone - 根据设备类型选择不同的 Storyboard

Ubuntu 上的 iPhone 应用程序开发

objective-c - 设置背景图片位置

ios - 合成带有尾随下划线的属性

ios - 从容器 View 以编程方式推送以查看 Controller