MBProgressHud视图自定义在Swift 3中不起作用而不显示?

时间:2017-06-21 06:40:02

标签: ios iphone swift swift3 mbprogresshud

我正在使用以下代码,但没有显示进度hud所以请帮助..smple nud显示正常但自定义不显示

let loadingHUD = MBProgressHUD() 

loadingHUD.mode = MBProgressHUDModeCustomView
loadingHUD.labelText = nil
loadingHUD.detailsLabelText = nil
let customView = UIView.init(frame: CGRect(x: 0, y: 0, width: 80, height: 80))

let gifmanager = SwiftyGifManager(memoryLimit:20)
let gif = UIImage(gifName: "miniballs1.gif")
let imageview = UIImageView(gifImage: gif, manager: gifmanager)
imageview.frame = CGRect(x: 0 , y: 0, width: customView.frame.width, height: customView.frame.height)
customView.addSubview(imageview)
customView.bringSubview(toFront: imageview)

loadingHUD.customView = customView
loadingHUD.customView.bringSubview(toFront: customView)
loadingHUD.show(true)

3 个答案:

答案 0 :(得分:4)

我在Swift 3中解决了这个问题

   var hud = MBProgressHUD()


 hud.backgroundColor = UIColor.clear


// Set an image view with a checkmark.
let gifmanager = SwiftyGifManager(memoryLimit:20)
let gif = UIImage(gifName: "eclipse.gif")
let imageview = UIImageView(gifImage: gif, manager: gifmanager)
hud.labelText = NSLocalizedString(string, comment: "")
hud.labelColor = UIColor.red

imageview.frame = CGRect(x: 0 , y: 0, width: 80 , height: 80)

let views = UIView.init(frame: CGRect(x: 0 , y: 0, width: 80 , height: 80))
views.backgroundColor = UIColor.black
views.addSubview(imageview)

hud.customView = views

hud.customView.backgroundColor = UIColor.clear
hud.dimBackground = true

    hud.show(true)

答案 1 :(得分:4)

尝试使用此库ACProgressHud-Swift

在xib文件中生成任何视图然后自定义并使用它。

For Show

ACProgressHUD.shared.showHUD(withStatus: “Your Message Name“)

隐藏

ACProgressHUD.shared.hideHUD()

答案 2 :(得分:0)

import UIKit

class Loader:  NSObject {


class func setup()
{
    MBProgressHUD.setDefaultMaskType(.Black)
    MBProgressHUD.setBackgroundColor(UIColor(white: 0, alpha: 0.7))
    MBProgressHUD.setForegroundColor(UIColor(white: 1, alpha: 1))

}

class func Show(message:String = "loading..."){

    MBProgressHUD.showWithStatus(message)
    UIApplication.sharedApplication().networkActivityIndicatorVisible = true

}

class func Hide(){
    MBProgressHUD.dismiss()
    UIApplication.sharedApplication().networkActivityIndicatorVisible = false
}
}

创建一个MBProgressHUD类并将其用作Loader.Show()或者您可以根据您的要求自定义它