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

问题描述 投票:5回答:3

我正在使用以下代码,但没有显示进度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)
ios iphone swift swift3 mbprogresshud
3个回答
4
投票

试试这个库ACProgressHud-Swift

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

对于秀

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

对于隐藏

ACProgressHUD.shared.hideHUD()

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)

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()或者您可以根据您的要求自定义它

© www.soinside.com 2019 - 2024. All rights reserved.