ios - Auto layout constraints for dynamic view -


i creating custom uicontrol ios(xamarin.ios). uicontrol consists of textfield , button. have creating custom control extending uiview

coplexity

the width of textfield given user , need rendered on runtime.

scenario: user given form in application can enter width of control, example, if user entered 50 , hits submit button, when custom uicontrol rendered in next page should take 50% of total screen width.

issue

i need apply auto layout constraints text field. , have added constraints, top , left constraints working expected. when rotate device right margin not changing proportionally

this.addconstraint (               nslayoutconstraint.create(textfield,nslayoutattribute.left,nslayoutrelation.equal,this, nslayoutattribute.left, 1 , 10)         );          this.addconstraint (             nslayoutconstraint.create(textfield,nslayoutattribute.right,nslayoutrelation.equal,this, nslayoutattribute.left, 1 , ((uiscreen.mainscreen.bounds.width * edittextwidth)/100)+10)         );          this.addconstraint (             nslayoutconstraint.create( textfield, nslayoutattribute.top, nslayoutrelation.equal,label, nslayoutattribute.top, 1, 30+10)         );          this.addconstraint (             nslayoutconstraint.create(textfield, nslayoutattribute.height, nslayoutrelation.equal, null, nslayoutattribute.noattribute, 0, 3 * 10)         ); 

i don't know how in xamarin explain how can done.

i assuming starting x , y co ordinates remain same.

the 2 constraints add start are:

nslayoutconstraint.create(textfield,nslayoutattribute.left,nslayoutrelation.equal,this, nslayoutattribute.left, 1 , 10)  nslayoutconstraint.create( textfield, nslayoutattribute.top, nslayoutrelation.equal,label, nslayoutattribute.top, 1, 30+10) 

the other 2 constraints should add constant height , width constraints of text field.

and when view loads, change constant of same constraints in array simple doing this:

constraintsarray = textfield.constraints; 

this set constaints initially.

now set view listen device orientation changes , update constants again:

nsnotificationcenter.defaultcenter                 .addobserver("uideviceorientationdidchangenotification", devicerotated );      private void devicerotated(nsnotification notification){         switch (uidevice.currentdevice.orientation){         case  uideviceorientation.portrait:             constraint.constant = ((uiscreen.mainscreen.bounds.width * edittextwidth)/100);             break;         case uideviceorientation.landscapeleft:         case uideviceorientation.landscaperight:             constraint.constant = ((uiscreen.mainscreen.bounds.height * edittextwidth)/100);         }     } 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -