I am a beginner in objective c. I am trying to design a UIButton
so that it's left side is always touches left side of screen and right side of UIButton
should always be on centre of screen. I am trying it on storyboard
with auto layout, but when I rotate the screen means UIButton
doesn't meet the condition. What constraint should I have to use for this?
How to place UiButton's right side is always on centre of screen?
104 views Asked by e.k At
1
Setting up constraint is not so simple as it seems, you can achieve more with constraints too. From your question i understood that you want UIButton from left side screen to cover half screen. To do so: 1) Add left margin constraint with constant 0(zero), this will start your button from left side of the screen. Now, how to make UIButton to fill half of the screen, You have to add little logic in you constraint. button with to the centre of screen =
screen.width/2
Here is how you can achieve with constraints.1)Right Click on Button, drag to main view, 2)From list Select Equal width, Usually this will makes your button same size of main view. 3)Select the width constraint of button (Must be in red Color) 4)Go to property inspector of constraint, 5) In multiplier filed change 1 to 0.5. This is how you can make your button half size of screen.