简体   繁体   English

如何在UIActivityIndi​​catorView后面添加黑色背景

[英]How can add black background behind the UIActivityIndicatorView

Hello I want to show a UIActivityIndicatorView on my UIViewController exactly like this 您好,我想在UIViewController完全像这样显示一个UIActivityIndicatorView

在此处输入图片说明

How can I draw a UIViewIndicator like this above image 我如何像上图一样绘制一个UIViewIndicator

I have tried this 我已经试过了

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)


    }

You could put it in another view that has a black background color. 您可以将其放在具有黑色背景色的另一个视图中。 Something like this. 这样的事情。 You could also add the 'Loading...' label in that view if you need it. 如果需要,您也可以在该视图中添加“正在加载...”标签。

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)
}

Use MBProgressHud library . 使用MBProgressHud库。

This is what you need :- 这就是您需要的:-

https://github.com/jdg/MBProgressHUD https://github.com/jdg/MBProgressHUD

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将UIActivityIndi​​catorView添加到UITableViewCell? - How to add UIActivityIndicatorView to UITableViewCell? 如何将UIActivityIndi​​catorView添加到WKWebView? - How to add UIActivityIndicatorView to WKWebView? 如何在UIAlertView的中心添加UIActivityIndi​​catorView? - How to add UIActivityIndicatorView at center of UIAlertView? UIPageViewController 中控制器背后的黑色背景 - Black background behind controllers in UIPageViewController 如何在 UI 表格视图后面放置黑色不透明背景? - How do I put a black opaque background behind a UI tableview? 无法将UIActivityIndi​​catorView添加到UIButton子类 - Can't add UIActivityIndicatorView to UIButton subclass 如何在UIPageViewController后面添加背景视频视图? - How to add a background video view behind a UIPageViewController? 如何在Swift中使用URLSession添加UIActivityIndi​​catorView? - How to add UIActivityIndicatorView by using URLSession in Swift? 如何将UIActivityIndi​​catorView添加到UITableView的底部,并在加载时进行切换 - How to add UIActivityIndicatorView to the bottom of UITableView, and toggle it on loadings 如何将 UIActivityIndi​​catorView 添加为 UITextField 的 rightView - How to add UIActivityIndicatorView as UITextField’s rightView
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM