swift3 - custom class swift setting constraints to superview -


i want create custom uiview can add view , have show red error message instagram in picture. able programmatically in view controller want create modular class can add view want show error. question how can add constraints superview in custom class?

for example how do:

    topanchor.constraint(equalto: view.topanchor, constant: 0)     leftanchor.constraint(equalto: view.leftanchor, constant: 0)     rightanchor.constraint(equalto: view.rightanchor, constant: 0)     widthanchor.constraint(equalto: errorlabel.frame.size.height,0) 

in custom class don't have in view controller? can access whatever superview's constraints view located @ top?

class customuialertview : uiview {     override init(frame: cgrect) {         super.init(frame: frame)     }      required init?(coder adecoder: nscoder) {         fatalerror("init(coder:) has not been implemented")     } } 

can give guidance on how approach this? feel missing basic.

i think best way pass superview parameter init method.

something that:

class customuialertview : uiview {     weak var parent:uiview     override init(frame: cgrect) {         super.init(frame: frame)     }      required init?(coder adecoder: nscoder) {         fatalerror("init(coder:) has not been implemented")     }     required init(frame:cgrect, superview:uiview) {         super.init(frame: frame)         self.parent = superview     } } 

Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -