ios - centering an object so vertical constraints are always even -


i need center uibutton('call') between uiview(the dialpad) , bottom layout guide. view align center x , align center y.

so, i'd have vertical constraints between view , call button , call button , bottom layout guide equal

the uiview ('dialpad') constraints enter image description here

the uibutton ('call') constained bottom layout guide. want spaced evenly between uiview , bottom layout guide

enter image description here

and storyboard preview shows different sizes , how call button not centered between uiview , bottom layout guide. extremely obvious in 4.7" layout

enter image description here

have tried doing @ runtime through constraints ? , approach follow : have constraints set current state need outlet button constraint (the 1 button bottom layout guide) viewcontroller (you outlet uikit control) , in viewwillappear or viewdidappear can write following code :

//here end y point of dial view .  cgfloat dialpadyendpos = self.dialpad.frame.origin.y + self.dialpad.frame.size.height;  //here space between dial view , bottom of view cgfloat spacebetweenviews = self.view.frame.size.height - dialpadyendpos ;  //here half of call button height .  cgfloat halfbtnheight = self.call.frame.size.height/2.0f ; //then set outlet constraint .  self.bottomconstraint.constant = (spacebetweenviews/2.0f)-halfbtnheight ;  [self.view layoutifneeded] ;  

i haven't tested code theoretically should work .


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -