admin管理员组文章数量:1123790
I have a UIButton in my UIViewController in my storyboard, and I'm trying to change it's background image, using transition animation:
extension UIButton {
func setBackgroundImageWithFade(_ image: UIImage?,
duration: TimeInterval = 1.25,
completion : ((Bool) -> Void)? = nil) {
// Create a crossfade animation
UIView.transition(with: self, duration: duration, options: .transitionCrossDissolve, animations: {
self.setBackgroundImage(image, for: .normal)
}, completion: completion)
}
}
I've tried to change the button's type, and also the Background property is set to 'Custom'. but nothing works - the image won't change!
I have a UIButton in my UIViewController in my storyboard, and I'm trying to change it's background image, using transition animation:
extension UIButton {
func setBackgroundImageWithFade(_ image: UIImage?,
duration: TimeInterval = 1.25,
completion : ((Bool) -> Void)? = nil) {
// Create a crossfade animation
UIView.transition(with: self, duration: duration, options: .transitionCrossDissolve, animations: {
self.setBackgroundImage(image, for: .normal)
}, completion: completion)
}
}
I've tried to change the button's type, and also the Background property is set to 'Custom'. but nothing works - the image won't change!
Share Improve this question edited yesterday Aviram Netanel asked yesterday Aviram NetanelAviram Netanel 13.6k9 gold badges49 silver badges72 bronze badges 2- A storyboard button is configuration based. You need to change its configuration's background's image. – matt Commented yesterday
- @matt sorry, I forgot to mention "extension UIButton" at the beginning... hope now it makes more sense. you are right, but I'm trying to change the image programmatically. – Aviram Netanel Commented yesterday
1 Answer
Reset to default 0So this is the solution that worked for me:
on the button's attributes inspector panel I changed the Type -> Custom and also the Style -> Default.
本文标签: UIButton setBackgroundImage doesn39t work Swift UIKitStack Overflow
版权声明:本文标题:UIButton setBackgroundImage doesn't work?! Swift UIKit - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736599532a1945190.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论