uibutton in image view

Hi all, please help... 🙂


I have got a view controller contains a uiimage view, and i put a uibutton within the uiimage view.


I am using size classes (width compact, high regular, all iphones portrait).


when i add constrain to the button, it changes possitions on different iphone screen.


I have checked a lot of size class tutorials, but all of them are like puting button in the center, or adding multiple buttons then evenly spread out.


Do anyone know any tutorial like adding only one button to the screen, and the button remains at the same postion?

First off, don't add subviews to a UIImageView. Add siblings. If that's what you've done (i.e. "within" actually means "placed on top of") then disregard.


Second, "remains at the same position" relative to what? Make your constraints between your button and the answer to that question.

Hi junkpile:


Thank you for your reply, and yes, "within" means "on top of".


I want to put an uibutton on top of an uiImageView, and at certain location.


I added an uibutton (size 94, 48, x: 238, y: 521) to the view, and put leading space to container margin (control + drag from button to view), and put trailing space to container, then vertical spacing to top layout guide. At this point, xcode shows :


trailingMargin = buttom.trailing + 48

Button.top = Top Layout Guide.bottom +501

Button.leading = leadingMargin+218


and got warning asking me to change the height from 48 to 30? not sure why it is doing this.


and if i bring up the previewer, the button will be at different location of the screen, and the button is not even showing on the 4-inch iphone.


please help.


regards


Jacky

I'll repeat what I said earlier: what should the button's position be relative to?


You said you have a constraint of 501 points from the top layout guide. On a 4" screen (568 points) that should put it at 521 points from the superview top, unless you have a navigation bar, in which case it would be 565 points from the superview top so only 3 points of it would be showing. It would be completely off screen on a 3.5" phone and would be up in the middle somewhere on a 4.7" or 5.5" screen.


If you want the button relative to the bottom of the screen on all devices, then make your constraint to the bottom.


It is warning you about changing the size to 30 points because that's the intrinsic content size (height) of a button. If you haven't set a constraint for the height, then it will use the intrinsic content size (30 points) at runtime. If you want it to be 48, set a height constraint of 48. You have to tell auto layout what you want - it doesn't read minds.

Hi Junkpile:


thanks for your feedback, but still cant make it work as the the image is still scaling at the same time.


could you please leave me an email so i can give you some screen shots?


regards


Jacky

uibutton in image view
 
 
Q