I’m trying to make simple meme app using Swift.I need to set up image at full screen.You can see Main StoryBoard with constraints here. But when im picking image that must fill full screen in portrait as result there is blank spaces in top and bottom. Similarly with landscape image but now spaces are on right and left. Anyone know how to fix this?
Set your UIImageView's contentMode to aspectFill.
Either in the storyboard…
or in code…
imageView.contentMode = .aspectFill
You can also implement a very handy third party library, easy to use : https://github.com/JanGorman/Agrume
It enables you to handle every kind of gestures, interactions, zooms etc.. on your UIImageView.
Thus, you won't have to worry about portrait/landscape constraints.
#Ashley Mills answer is the answer, mine is just an advice.
Related
I've run into a problem with UIButtons in Stack Views. The image that the buttons are set to get squished whenever there's not enough vertical space for them, such as when the phone is in horizontal orientation, or on a small device.
I did find a solution, by running: button.imageView?.contentMode = .scaleAspectFit in viewDidLoad() but it seems like the wrong way to do it.
I assume that the best way to do this would be within Storyboard. First of all, is this the best way? Second of all, how would I do it? (I'm still very new to iOS development)
I have tried using in the attributes inspector, but that doesn't seem to have done anything. Maybe I'm missing a step.
Storyboard vs Code
There are people that prefer code over storyboard. There are people that prefer storyboard over code. There is no wrong or right way since both ways are correct. Do whatever you think is better and/or easier.
Setting the Content Mode through the Storyboard
I don't think this is possible. I think the Content Mode you were trying to set is the Content Mode of the button you had selected. I don't think there is another Content Mode dropdown for the embedded UIImageView in the UIButton. Your best bet would be to set the .imageView.contentMode through code like you already did.
I hope this question makes sense.
I have 2 images in my viewcontroller. One is for a background and the second I need to move around on top of that image freely. I am using autolayout for the background image, but when I test on different devices the second image is not in the proper place because I am not using the autolayout on it and therefore it does not move correctly.
How can I move the image to be in the proper place. Is there some way to set it properly in code. I guess I mean how could I set the autolayout in code since this image will have many positions it needs to move to.
This issue is really frustrating and getting me crazy.
I've read everything about AutoLayout and so on, but it happens all the time.
My interface has a view with an image view as background and a smaller subview on top of it (corresponding to a field in my image). I've tried everything but it looks like the subview does not scale accordingly with my image when switching through devices.
By the way, the IB preview does not show what i real get when running the iOS Simulator, is that normal?
Why? What do i do wrong? I'm not sure what else to try!
http://i58.tinypic.com/34xqtc6.png
EDIT: i cannot post images :(
I have setup a githubrepo regarding your case, kindly have a look
https://github.com/usamaiqbal83/TestingProject
Constraints for Background Image View:
Constraints for Front View
the most important thing to remember is ofcourse the constraint equation
FirstItem.Attribute1 = (SecondItem.Attribute2 * Multiplier) + Constant
Instead of subview use Container View.
I have a VC with two imageViews. One takes up the whole screen, the other is actually slightly larger and can be moved around on the screen (Pan Gesture).
When the device changes orientation only the static view changes orientation, or just updates its frame maybe (automatically).
The second Pan UIImageView does not move. Is there a reason for this, or a switch to make this happen somewhere possibly in the storyboard properties of the UIImageView itself? I would like the view to move too.
I understand that an option would be to use the methods that confirm the orientation has completed a change and transform the imageView myself, which is not a problem... but checking I am not missing something that could do this for me automatically first.
Ensure you are using correct AutoResizeMasks on the imageview. Provide your code or storyboard description for a more complete answer.
-Additionally if you are using AutoLayout, you may need to add the appropriate constraints (making it slightly larger than the view may confuse it as to your intention without proper suggestions via constraints).
So I am new to autolayout in iOS and so I have run into a problem.
My program has 2 imageviews which can be dragged around,pinched, zoomed in and rotated. The user should be able to drag the image views anywhere on the screen. So basically I dont want constraints holding my images in place. I need autolayout to be off for the 2 image views alone (and I know thats not possible).
So whats happening now is when I run the program, the image views can be dragged to anywhere in the screen but when I rotate it or pinch to zoom it, the image moves from its current position and gets placed at the center of the screen, and there it will be zoomed or rotated.( Center contraints are there and they are on lowest priority). I can't seem to delete the constraints either.
Is there anyway I can avoid the constraints just for the image views???If not, what can be the solution to my problem??
override -(void) layoutSubviews in your UIViewController
That should do the trick :)
Take a look at this question. It explains how to disable auto layout for a specific uiview at runtime.
Can I disable autolayout for a specific subview at runtime?