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
the uibutton ('call') constained bottom layout guide. want spaced evenly between uiview , bottom layout guide
and storyboard preview shows different sizes , how call button not centered between uiview , bottom layout guide. extremely obvious in 4.7" layout
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
Post a Comment