UIEdgeInsets.init 未在 Xcode 中处理 Swift

UIEdgeInsets.init is Not working on Swift in Xcode

我正在处理 ios 项目。我想调整文本视图的内部边距值'UIEEdgeInsets.I 试图使用 'init'。但它显示错误。

Use of unresolved identifier 'bottom'

参考了官方文档的使用,没有发现问题。我错过了什么?

用法

    @IBAction func NextButtonfuc(_ sender: Any) {
        if  agreeOneCheck.isSelected != true ||
            agreeThreeCheck.isSelected != true ||
            allAgreeCheck.isSelected != true ||
            agreeTwoCheck.isSelected != true
        {
            let storyboard = UIStoryboard(name: "Main", bundle: nil)
            let myAlert = storyboard.instantiateViewController(withIdentifier: "ModalViewController") as! ModalViewController
            myAlert.modalPresentationStyle = .overCurrentContext
            myAlert.modalTransitionStyle = .crossDissolve
            myAlert.modalCustomAlert.textContainerInset = UIEdgeInsets.init(top: 100.0, left: 0.0, bottom: 0.0, right: 0.0) // get Error
            myAlert.text = "OK Thanks"
            self.present(myAlert, animated: false, completion: nil)

        }
    }

***************************编辑开始 ****************** *************************

我参考答案修改了代码

    @IBAction func NextButtonfuc(_ sender: Any) {
        if  agreeOneCheck.isSelected != true ||
            agreeThreeCheck.isSelected != true ||
            allAgreeCheck.isSelected != true ||
            agreeTwoCheck.isSelected != true
        {
            let storyboard = UIStoryboard(name: "Main", bundle: nil)
            let myAlert = storyboard.instantiateViewController(withIdentifier: "ModalViewController") as! ModalViewController
            myAlert.modalPresentationStyle = .overCurrentContext
            myAlert.modalTransitionStyle = .crossDissolve
            let insets = UIEdgeInsets.init(top: 100.0, left: 0.0, bottom: 0.0, right: 0.0)
            myAlert.modalCustomAlert.textContainerInset = insets //  Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value
            myAlert.text = "OK Thanks"
            self.present(myAlert, animated: false, completion: nil)

        }
    }

get error : Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value

***************************编辑结束 ****************** *************************

************************编辑第二个****************** *************************

ModalViewController

import Foundation
import UIKit

class ModalViewController : UIViewController {

    var text: String?


    @IBOutlet weak var modalCustomAlert: UITextView!
    @IBOutlet weak var okButton: UIButton!

    @IBAction func okPress(_ sender: Any) {
        self.dismiss(animated: true, completion: nil)
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        modalCustomAlert.layer.cornerRadius = 8
        self.modalCustomAlert.text = text
    }





    func changeViewFont() {
        let screenWidth = UIScreen.main.bounds.size.width
        let screenHeight = UIScreen.main.bounds.size.height

        if screenWidth < 375 {
            // iPhone 4inch and 3.5inch. Smaller than iPhone 8
            // Call change font
            modalCustomAlert.font = UIFont.systemFont(ofSize: 12)

            okButton.titleLabel?.font = UIFont.systemFont(ofSize: 12)

        }
        if screenHeight > 667 {

            modalCustomAlert.font = UIFont.systemFont(ofSize: 16)

            okButton.titleLabel?.font = UIFont.systemFont(ofSize: 16)
        }
    }


}

***************************编辑结束 ****************** *************************

想了想把值传给Controllerclass解决了这个问题

    @IBAction func NextButtonfuc(_ sender: Any) {
        if  agreeOneCheck.isSelected != true ||
            agreeThreeCheck.isSelected != true ||
            allAgreeCheck.isSelected != true ||
            agreeTwoCheck.isSelected != true
        {
            let storyboard = UIStoryboard(name: "Main", bundle: nil)
            let myAlert = storyboard.instantiateViewController(withIdentifier: "ModalViewController") as! ModalViewController
            myAlert.modalPresentationStyle = .overCurrentContext
            myAlert.modalTransitionStyle = .crossDissolve
            let insets = UIEdgeInsets.init(top: 100.0, left: 0.0, bottom: 0.0, right: 0.0)
            myAlert.marginValue = insets 
            myAlert.text = "OK Thanks"
            self.present(myAlert, animated: false, completion: nil)

        }
    }

ModalViewController

    var text: String?
    var marginValue : UIEdgeInsets?
...

    override func viewDidLoad() {
        super.viewDidLoad()
        modalCustomAlert.layer.cornerRadius = 8
        self.modalCustomAlert.text = text
        self.modalCustomAlert.textContainerInset = marginValue!
    }