Computer >> कंप्यूटर ट्यूटोरियल >  >> प्रोग्रामिंग >> iOS

iOS में डिफॉल्ट अलर्ट डायलॉग की चौड़ाई और ऊंचाई कैसे नियंत्रित करें


ऐसे उदाहरण होंगे जहां आपको iOS एप्लिकेशन विकसित करते समय अलर्ट की चौड़ाई और ऊंचाई को नियंत्रित/मैनिपुलेट करने की आवश्यकता हो सकती है। यदि आप इससे परिचित नहीं हैं, तो यह आपको परेशान कर सकता है।

यहां हम देखेंगे कि डिफॉल्ट अलर्ट बॉक्स की ऊंचाई और चौड़ाई को कैसे नियंत्रित करें, ऊंचाई और चौड़ाई को नियंत्रित करने के लिए हम NSLayoutConstraint का उपयोग करेंगे।

शुरुआत करते हैं

चरण 1: प्रोजेक्ट बनाएं

Xcode खोलें → New Project → Single View Application → नाम दें "changeheightandwidth"

चरण 2: बटन बनाएं

Main.storyboard में एक बटन बनाएं और उसका नाम "tap" रखें, ViewController.swift में @IBAction बनाएं और आउटलेट का नाम btnATap रखें।

चरण 3: बटन मेथड में कोड लिखें

UIAlertController का ऑब्जेक्ट बनाएं।

let alert = UIAlertController(title: "Your Title", message: "Your Message", preferredStyle: UIAlertController.Style.alert)

हाइट और विड्थ कंस्ट्रेंट्स बनाएं।

// हाइट कंस्ट्रेंट
let constraintHeight = NSLayoutConstraint(
    item: alert.view!,
    attribute: NSLayoutConstraint.Attribute.height,
    relatedBy: NSLayoutConstraint.Relation.equal,
    toItem: nil,
    attribute: NSLayoutConstraint.Attribute.notAnAttribute,
    multiplier: 1,
    constant: 100)
alert.view.addConstraint(constraintHeight)

// विड्थ कंस्ट्रेंट
let constraintWidth = NSLayoutConstraint(
    item: alert.view!,
    attribute: NSLayoutConstraint.Attribute.width,
    relatedBy: NSLayoutConstraint.Relation.equal,
    toItem: nil,
    attribute: NSLayoutConstraint.Attribute.notAnAttribute,
    multiplier: 1,
    constant: 300)
alert.view.addConstraint(constraintWidth)

एक्शन्स के साथ अलर्ट व्यू प्रस्तुत करें।

let cancel = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
alert.addAction(cancel)
let OKAY = UIAlertAction(title: "Done", style: .default, handler: nil)
alert.addAction(OKAY)
self.present(alert, animated: true, completion: nil)

चरण 4: कोड चलाएं

पूरे कोड के लिए:

@IBAction func btnATap(_ sender: Any) {
    let alert = UIAlertController(title: "Your Title", message: "Your Message", preferredStyle: UIAlertController.Style.alert)
    
    // हाइट कंस्ट्रेंट
    let constraintHeight = NSLayoutConstraint(
        item: alert.view!,
        attribute: NSLayoutConstraint.Attribute.height,
        relatedBy: NSLayoutConstraint.Relation.equal,
        toItem: nil,
        attribute: NSLayoutConstraint.Attribute.notAnAttribute,
        multiplier: 1,
        constant: 100)
    alert.view.addConstraint(constraintHeight)
    
    // विड्थ कंस्ट्रेंट
    let constraintWidth = NSLayoutConstraint(
        item: alert.view!,
        attribute: NSLayoutConstraint.Attribute.width,
        relatedBy: NSLayoutConstraint.Relation.equal,
        toItem: nil,
        attribute: NSLayoutConstraint.Attribute.notAnAttribute,
        multiplier: 1,
        constant: 300)
    alert.view.addConstraint(constraintWidth)
    
    let cancel = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
    alert.addAction(cancel)
    let OKAY = UIAlertAction(title: "Done", style: .default, handler: nil)
    alert.addAction(OKAY)
    self.present(alert, animated: true, completion: nil)
}

iOS में डिफॉल्ट अलर्ट डायलॉग की चौड़ाई और ऊंचाई कैसे नियंत्रित करें

  1. Windows Terminal विंडो की डिफ़ॉल्ट Height और Width कैसे बदलें Windows Terminal विंडो की डिफ़ॉल्ट Height और Width कैसे बदलें

    जो लोग Windows Terminal का उपयोग करते हैं, वे जानते हैं कि यह कितना महत्वपूर्ण और अक्सर कितना बार उपयोग किया जाता है। आप खुद को हर बार इसका उपयोग करने पर डिफ़ॉल्ट Windows Terminal विंडो के आकार को व्यवस्थित करते हुए पा सकते हैं। शायद यह आपके लिए बहुत छोटा है या इसके विपरीत। हालांकि यह समायोजन करना क

  1. OS X और iOS में डिफ़ॉल्ट कैलेंडर सेट करें OS X और iOS में डिफ़ॉल्ट कैलेंडर सेट करें

    जब भी आप अपने मैक या iOS डिवाइस पर कैलेंडर ऐप में एक नया इवेंट बनाते हैं, तो इवेंट उस कैलेंडर में जुड़ जाता है जिसे आपके डिवाइस पर डिफ़ॉल्ट के रूप में सेट किया गया है। यदि आपके पास कई कैलेंडर हैं और आप उन्हें विभिन्न उद्देश्यों के लिए उपयोग करते हैं, तो डिफ़ॉल्ट कैलेंडर हमेशा वह कैलेंडर नहीं हो सकता

  1. iPhone पर iOS 11 कंट्रोल सेंटर को कैसे अनुकूलित करें iPhone पर iOS 11 कंट्रोल सेंटर को कैसे अनुकूलित करें

    iPhone और iPad के लिए Apple का नवीनतम रिलीज़, iOS 11, एक पुनः डिज़ाइन किया गया और मॉड्यूलराइज़्ड कंट्रोल सेंटर पेश करता है। यह नया कंट्रोल सेंटर काफी 3D-Touch जेस्चर, नई एनिमेशन, और अनुकूलन क्षमता पेश करता है। इसके अलावा, नए कंट्रोल बिल्ट-इन हैं जो पहले ऐप संस्करणों में डाउनलोड या iOS पर उपयोग के ल