Accessing IBOutlet from another class

空扰寡人 提交于 2019-12-05 10:44:40
Christian Wörz

You access a generic ViewController, but need to use an existing UIView. Do something like this:

class Test: UIViewController {

    class func set_cornerRadius(yourView: UIView, radius: CGFloat) {
        yourView.layer.cornerRadius = radius
    }
}

That way, you pass the UIView you want to set the corner-radius.

You extend your ViewController class like so:

extension ViewController {
    func set_cornerRadius(radius: CGFloat) {
         someButton.layer.cornerRadius = radius
    }
}

Now you can call this method in your original ViewController file using: set_cornerRadius(someValue) in your viewDidLoad or wherever you want. You can put this extension in a different file.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!