ios - How to modify programmatically constraints of UIButton -


i have 2 buttons different constraints write in storyboard. in code, have tell first button take same constraint of second button (height, width, and position) not know how without passing "subview". have 2 outlets buttons.

@iboutlet weak var likesbutton: uibutton!     @iboutlet weak var sharebutton: uibutton! 

my interface build :

-

view      a)...view      b)...view      c) contentview          1)likebutton          2)sharebutton          3)...      d)... 

i tried :

      self.contentview.translatesautoresizingmaskintoconstraints = false         self.sharebutton.removeconstraints(self.sharebutton.constraints) // old constraints         self.sharebutton.addconstraints(self.likebutton.constraints) // new constraints         self.sharebutton.updateconstraintsifneeded()         self.sharebutton.layoutifneeded() 

and after have error :

 *** terminating app due uncaught exception 'nsgenericexception', reason: 'unable install constraint on view.  constraint reference outside subtree of view?  that's illegal. constraint:<nslayoutconstraint:0x14cfe7600 h:[uibutton:0x14cfb7bd0(40)]> view:<uibutton: 0x14e30fa60; frame = (494 528; 26 31); opaque = no; autoresize = rm+bm; layer = <calayer: 0x14e30f410>>' 

thx in advance.

does constraint reference outside subtree of view?

this if said...

does constraints of likebutton reference outside subtree of sharebutton?

so, likebutton constraint references (like likebutton itself) outside sharebuttons view hierarchy. can't added way.

you instead do:

self.view.removeconstraints(self.sharebutton.constraints) self.view.addconstraints(self.likebutton.constraints) 

but won't accomplish whatever you're trying do.

a constraint more number , dimension. defines 2 objects constrained. trying map 1 views constraints won't work because doesn't change views referenced in constraint.

you can hack out way using outlets various constraints , pulling constraint constants out of 1 view , assigning them other.


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -