MBProgressHUD इंटीग्रेशन
Swift में MBProgressHUD उपयोग करने के लिए हमें पहले एक पॉडफाइल बनाने की आवश्यकता है यदि यह पहले से मौजूद नहीं है।
टर्मिनल पर जाएं और अपने प्रोजेक्ट डायरेक्टरी में डायरेक्टरी बदलें फिर पॉड इनिशियलाइज़ करें और बाद में MBProgressHUD इंस्टॉल करें।
cd /projectDirectory
pod init
open podfile
फिर पॉडफाइल में निम्नलिखित लाइन जोड़ें और टर्मिनल पर वापस जाएं और उसी डायरेक्टरी में नीचे दी गई कमांड चलाएं।
pod 'MBProgressHUD', '~> 1.1.0'
pod install
एक बार जब आप ये कमांड चलाते हैं तो MBProgressHUD आपके प्रोजेक्ट में इंस्टॉल हो जाएगा, अब आप इस लाइब्रेरी को जहां भी उपयोग करना चाहते हैं उस ViewController में इम्पोर्ट कर सकते हैं, या आप UIViewController का एक्सटेंशन बना सकते हैं और इस मेथड का उपयोग कर सकते हैं।
विधि 1: ViewDidLoad में जोड़ना
let indicator = MBProgressHUD.showAdded(to: self.view, animated: true)
indicator.label.text = "Indicator"
indicator.isUserInteractionEnabled = false
indicator.detailsLabel.text = "fetching details"
indicator.show(animated: true)
इसी तरह, आप व्यू से इंडिकेटर छिपाने के लिए निम्नलिखित का उपयोग कर सकते हैं।
MBProgressHUD.hide(for: self.view, animated: true)
विधि 2: ग्लोबली एक्सेसिबल बनाने के लिए एक्सटेंशन बनाना
extension UIViewController {
func showIndicator(withTitle title: String, and description: String) {
let indicator = MBProgressHUD.showAdded(to: self.view, animated: true)
indicator.label.text = title
indicator.isUserInteractionEnabled = false
indicator.detailsLabel.text = description
indicator.show(animated: true)
}
func hideIndicator() {
MBProgressHUD.hide(for: self.view, animated: true)
}
}
जब हम इनमें से किसी को भी अपने डिवाइस पर चलाते हैं, तो हमें निम्नलिखित परिणाम मिलता है:
