MBProgressHud 视图自定义在 Swift 3 中不起作用并且不显示?
MBProgressHud View Customization Not Work In Swift 3 And Not Showing?
我正在使用以下代码但不显示进度 HUD 所以请帮助 that.simple HUD 显示正常但自定义不显示
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)
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
}
}
制作一个 class 的 MBProgressHUD 并将其用作 Loader.Show()
或者您可以根据需要自定义它
我在 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)
试试这个库 ACProgressHud-Swift
在 xib 文件中创建任何视图,然后自定义并使用它。
展示
ACProgressHUD.shared.showHUD(withStatus: “Your Message Name“)
隐藏
ACProgressHUD.shared.hideHUD()
我正在使用以下代码但不显示进度 HUD 所以请帮助 that.simple HUD 显示正常但自定义不显示
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)
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
}
}
制作一个 class 的 MBProgressHUD 并将其用作 Loader.Show()
或者您可以根据需要自定义它
我在 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)
试试这个库 ACProgressHud-Swift
在 xib 文件中创建任何视图,然后自定义并使用它。
展示
ACProgressHUD.shared.showHUD(withStatus: “Your Message Name“)
隐藏
ACProgressHUD.shared.hideHUD()