Ios 如何在UIActivityIndicatorView后面添加黑色背景
您好,我想在我的Ios 如何在UIActivityIndicatorView后面添加黑色背景,ios,swift,uiactivityindicatorview,Ios,Swift,Uiactivityindicatorview,您好,我想在我的UIViewController上显示一个UIActivityIndicatorView,就像这样 我怎样才能像上图那样绘制UIViewIndicator 我试过这个 func showIndicatorView(){ let loadingIndicator = UIActivityIndicatorView(frame: CGRectMake(0, 0, 50, 50)) loadingIndicator.layer.cornerRadiu
UIViewController
上显示一个UIActivityIndicatorView
,就像这样
我怎样才能像上图那样绘制UIViewIndicator
我试过这个
func showIndicatorView(){
let loadingIndicator = UIActivityIndicatorView(frame: CGRectMake(0, 0, 50, 50))
loadingIndicator.layer.cornerRadius = 05
loadingIndicator.opaque = false
loadingIndicator.backgroundColor = UIColor(white: 0.0, alpha: 0.6)
loadingIndicator.center = self.view.center;
loadingIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.Gray
loadingIndicator.color = UIColor.whiteColor()
loadingIndicator.startAnimating()
self.view.addSubview(loadingIndicator)
}
您可以将其放在另一个具有黑色背景色的视图中。像这样的。如果需要,还可以在该视图中添加“加载…”标签
func showIndicatorView(){
let loadingIndicator = UIActivityIndicatorView(frame: CGRectMake(0, 0, 50, 50))
let backgroundView = UIView()
backgroundView.layer.cornerRadius = 05
backgroundView.clipsToBounds = true
backgroundView.opaque = false
backgroundView.backgroundColor = UIColor(white: 0.0, alpha: 0.6)
loadingIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.Gray
loadingIndicator.color = UIColor.whiteColor()
loadingIndicator.startAnimating()
let loadingLabel = UILabel()
loadingLabel.text = "Loading..."
let textSize: CGSize = loadingLabel.text!.sizeWithAttributes([NSFontAttributeName: loadingLabel.font ])
loadingLabel.frame = CGRectMake(50, 0, textSize.width, textSize.height)
loadingLabel.center.y = loadingIndicator.center.y
backgroundView.frame = CGRectMake(0, 0, textSize.width + 70, 50)
backgroundView.center = self.view.center;
self.view.addSubview(backgroundView)
backgroundView.addSubview(loadingIndicator)
backgroundView.addSubview(loadingLabel)
}
您可以将其放在另一个具有黑色背景色的视图中。像这样的。如果需要,还可以在该视图中添加“加载…”标签
func showIndicatorView(){
let loadingIndicator = UIActivityIndicatorView(frame: CGRectMake(0, 0, 50, 50))
let backgroundView = UIView()
backgroundView.layer.cornerRadius = 05
backgroundView.clipsToBounds = true
backgroundView.opaque = false
backgroundView.backgroundColor = UIColor(white: 0.0, alpha: 0.6)
loadingIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.Gray
loadingIndicator.color = UIColor.whiteColor()
loadingIndicator.startAnimating()
let loadingLabel = UILabel()
loadingLabel.text = "Loading..."
let textSize: CGSize = loadingLabel.text!.sizeWithAttributes([NSFontAttributeName: loadingLabel.font ])
loadingLabel.frame = CGRectMake(50, 0, textSize.width, textSize.height)
loadingLabel.center.y = loadingIndicator.center.y
backgroundView.frame = CGRectMake(0, 0, textSize.width + 70, 50)
backgroundView.center = self.view.center;
self.view.addSubview(backgroundView)
backgroundView.addSubview(loadingIndicator)
backgroundView.addSubview(loadingLabel)
}
使用MBProgressHud库 这就是您需要的:-
使用MBProgressHud库 这就是您需要的:-
是的,我需要装货。。也。。。你能不能在你的代码中也加上这个,我也可以这样说,但是…你用的是XIB还是故事板?它的方式更容易和更干净,在那里做这件事,而不是从代码。我使用的故事板,你可以创建一个自定义视图那里。但是如果你不想,我用标签更新了我的答案。不过我没有测试它。它正在用加载器显示标签,但是有一些布局问题。你能试试你那边的代码吗,这样你就知道了是的,我需要加载。。也。。。你能不能在你的代码中也加上这个,我也可以这样说,但是…你用的是XIB还是故事板?它的方式更容易和更干净,在那里做这件事,而不是从代码。我使用的故事板,你可以创建一个自定义视图那里。但是如果你不想,我用标签更新了我的答案。不过我没有测试它。它正在用加载器显示标签,但是有一些布局问题。你能试试你那边的代码吗