Ios 如何在Swift中添加GIF背景的UIButtons?
我发现这段代码可以在登录屏幕上添加GIF背景,效果非常好Ios 如何在Swift中添加GIF背景的UIButtons?,ios,swift,uibutton,swift2,ios9,Ios,Swift,Uibutton,Swift2,Ios9,我发现这段代码可以在登录屏幕上添加GIF背景,效果非常好 import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() let filePath = NSBundle.mainBundle().pathForResource("MovingClouds", ofType: "gif") let gif = NSData(c
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let filePath = NSBundle.mainBundle().pathForResource("MovingClouds", ofType: "gif")
let gif = NSData(contentsOfFile: filePath!)
let webViewBG = UIWebView(frame: self.view.frame)
webViewBG.loadData(gif!, MIMEType: "image/gif", textEncodingName: "utf-8", baseURL: NSURL())
webViewBG.userInteractionEnabled = false;
self.view.addSubview(webViewBG)
let filter = UIView()
filter.frame = self.view.frame
filter.backgroundColor = UIColor.blackColor()
filter.alpha = 0.05
self.view.addSubview(filter)
let welcomeLabel = UILabel(frame: CGRectMake(0, 100, self.view.bounds.size.width, 100))
welcomeLabel.text = "KeepON"
welcomeLabel.textColor = UIColor.whiteColor()
welcomeLabel.font = UIFont(name: "Zapfino", size: 35)
welcomeLabel.textAlignment = NSTextAlignment.Center
self.view.addSubview(welcomeLabel)
}
这显示了我的GIF背景和标题,但当我尝试在View Controller的故事板中添加按钮时,它们在我运行应用程序时不会出现,只显示带有标题的GIF背景,我不想使用代码添加按钮
有什么想法吗?
谢谢这是因为您正在现有视图的顶部添加子视图。使用
insertSubView(webViewBG,atIndex:0)代替addSubView
代码>谢谢,你知道如何调整GiF的大小吗?因为它在打开自动布局时看起来更小,所以这是一个web视图。所以我不知道,你有什么特别的理由想要它作为一个web视图吗?因为uiimageview支持动画,而且它比为视图提供web浏览器要好得多。顺便说一句,如果这回答了你的问题,请将其标记为一个答案,以便人们知道。不,没有特别的原因,这是我找到的唯一可行的解决方案,所以我只能选择我的GIF作为我选择的普通图像?谢谢你提供我不知道的信息,看看这个,它会帮你的。如果您选择ImageView路线,则它具有图像缩放功能。是的,但是你可以看看目标C,看看swift,然后学习如何从2中得到答案