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

标签 ios swift uiactivityindicatorview

你好,我想在我的 UIViewController 上显示一个 UIActivityIndi​​catorView,就像这样

enter image description here

我怎样才能画出像上图这样的 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)


    }

最佳答案

您可以将它放在另一个具有黑色背景颜色的 View 中。像这样的东西。如果需要,您还可以在该 View 中添加“正在加载...”标签。

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

关于ios - 如何在 UIActivityIndi​​catorView 后面添加黑色背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36301606/

相关文章:

ios - 适用于 iOS 的 phoneGap 应用程序 : if application works in xCode device emulator

ios - CLLocation 速度不显示在 UIView 上

swift - 使用 GeneratorOf 结构实现 SequenceType 的自定义列表数据结构

arrays - Swift - 检查 Array<AnyObject> 是否包含 UIColor

ios - 为什么我的按钮在 Swift Playgrounds 中不起作用?

iphone - 加载新视频时隐藏 MPMoviePlayerController

ios - ActivityIndi​​cator 边界图形错误

android - 在 Android/iOS 上模拟多人游戏技术

ios - 如何在 UITableViewController 中显示 UIActivityIndi​​catorView?

iOS Swift PerformSegueWithIdentifier 用于发送数据