swift2 - Swift Constraints in Subclass -
i wondering if there way access constraints subclass. have custom view. i'm not sure if can access constraint have set in ui, tried creating constraint subclass itself.
class performanceview: uiview { func initialize() { let heightconstraint = nslayoutconstraint(item: self, attribute: .height, relatedby: .equal, toitem: superview, attribute: .height, multiplier: 0.47, constant: 0); superview.addconstraint(heightconstraint) } }
the above code not complete. showing attempting do. 2 questions.
1) can access constraint on ui subclass. 2) if not, how can create height constraint in subclass half of superview height.
and have performanceview class view can see performance view in left. 4 of them.
if understand question correctly, answer yes, there way. can drag outlets constraints performanceview using assistant editor.
as adjunct - can modify constraints in code using .constant. modifying priorities not supported though.
heightconstraint.constant = 230.0 //or other value
in order dragging outlets have make sure identified performanceview in storyboard editor. select performanceview in left column. type "performanceview" highlighted field in right column shown below , hit return. should go.
Comments
Post a Comment