How to define a class and module for a view created programmatically in fast

Let's say I create a view like this:

let myView = UIView(frame: CGRect(x: 0, y: 0, width: 50, height: 50))
self.view.addSubview(myView)

How can I give this view custom classand modulehow would I be in IB?

I was either looking for the wrong thing or no one was asking this question. I also tried nothing, because I can’t figure out where to start.

Update:

This is what I mean by adding classand module, as in IB:

enter image description here

+4
source share
1 answer

Just create an instance instead UIView.

Assuming this is your custom view:

class MyCustomView: UIView {
    //...
}

Here's how to do it:

let myView = MyCustomView(frame: CGRect(x: 0, y: 0, width: 50, height: 50))
self.view.addSubview(myView)

- , class MyCustomView: UIView.... iOS ( ) . " " Xcodes Inspector :

+4

Source: https://habr.com/ru/post/1673298/


All Articles