I am unable to find the Placeholder menu. Attaching my screenshot.
Is there any way to easily add constraints. It took me more than 2 hours just to resolve the constraints.? And the pic seems to be differently oriented in different simulators even after using the Editor> Size to Fit Option.
Would highly appreciate the help.
Thanks.
The easiest way to add constraints is by using "Pin" (second from the right in the attached image), which is located at the very bottom of the interface builder.
If you're having some trouble understanding AutoLayout, I recommend reading Apple's documentation https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/AutolayoutPG/
Let me know if you need further clarification.
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 am working on auto layout and making those UIIMages as Button.
I would like to make those button to be clicked and switch the images
as well as showing some words in the label.
In this case what should I do?
In addition, as it is shown, the auto layout ratio is different only from the iPhone SE. In. this case What should I consider?
Many thanks,
The first thing you need to learn is auto layout. Start with basic Always go with Apple's doc first
This one I likes he is good and you will also find how to use buttons as image view, using card game example, check other tutorials also very helpfull.
Stanford university autolayout by Michel Deiman
As far, your question just gives your label Horizontal in the container constraints(open storyboard in the right bottom third from last (allin) click on it popUp will open), and 20 bottom to the buttons and it will be in the centre. Every elements need x,y height and width so it knows exactly where to place, so you also need to give constraints to the buttons, Learn stackView to understand how to place your button without giving many constraints to each button and stack view will handle it for you, try hide and show to one of the button and magically stack view will adjust all adjustment. I suggest before staring Do read apple's doc first.
And Your question is too broad to answer, so read and try adding different constraints based on your need and ask a specific question(after trying by yourself) like why this label getting cut what constraints should i add so people know exactly what you want to achieve, people are always ready to help, just ask the right question.
happyCoding
"It just works", or does it?
So I was going nuts trying to fit one ScrollView into another.
I get to the point when I actually made two separate xib files, did a scrollable label in one, and a scrollable image in another. Both are works perfectly in separate xib's.
After that I manage to open xib files as simple text(looks like they are formatted as XML or something similar) and simply cut scrollable image view(with all of superviews that I needed) into my main.(containing scrollable label)
So the idea was simple yet beautiful, I was like 90 percent sure it is going to work, because I inserted all the necessary view-scrollView-contentView stuff. And it is not. As you can see guys, image is big enough, views setted to be large and you can barely see tiny bit of it. So it SHOULD be scrollable, right?
Label with text keeps scrolling just fine, but the image wont move.
I was also trying to get scroll enabled via code, setting property to YES, but it wont help.
I also tried disabling auto-layout, thinking that it could be easier, but it was not much luck on the first attempt. Will be great to hear you guys thoughts, maybe I should disable auto-layout and try it out the old-way? Or is there a way to solve this puzzle as is?
Maybe my question was a bit long and not much of a readable, sorry for that guys, anyway I found my answer and will post a solution for any of you guys wondering about the same thing.
Just a reminder, I was trying to achive scrollable text+ scrollable image. Text should be scrolled up/down and the image should be scrolled in all directions.
So I find my previous attempt almost completely broken and started fresh(couple of times) and in the end I find the configuration that suits my needs.
Matter of fact, this particular configuration works almost exactly out of the box, most of the trick is get the right views in position. After that you just have to add missing constraints from the "Editor"->"Resolve layout issues" menu and get rid of few nonsense constraints that IB add god know why.(like those ones that adds 200pt blank space at the bottom or so)
After that you'll be pretty much set. If not, refer to the picture link, or github repo. Hope that will help someone.
So, i've been looking anywhere an explanation about how to implement Mirroring on Storyboard's Auto Layout - not programmatically.
I have an app that support a few languages and when i turn the language to Hebrew, for example, i have a label that change it's text to hebrew. so far so good. what i want to do next is to change the label's place like a mirror.
Can anyone help me understand how to do it on Storyboard Auto Layout?
Thanks.
After doing some research, i found the answer:
First, you have to implement an Internationalization. you can follow Ray's Wenderlich tutorial for Internationalization by enter this link:
http://www.raywenderlich.com/64401/internationalization-tutorial-for-ios-2014 .
Now, on Storyboard, all you have to do is putting some constraints to your label:
put trailing and leading constraints to the label you want to reflect like a mirror when the user switch the language, and that's it.
It's much more easy then design a new Storyboard and you're using the elements that Apple gave you, so i guess it's the right way too.
Hope it helps.
I'm using storyboard.
And I have a toolbar with toolbarButtonItems separated by flexible spaces.
I want labels for each buttons. So I put labels in storyboard, but when rotating the device to landscape, labels are not aligned with buttons.
How can I solve this?
Any suggestions are welcome.
Kindest regards,
Well good sir, like many before you, you're presented with a two options.
Use Auto-Layout's Constraint system to describe what you want.
Use -layoutSubviews, and manually reposition the views in your ViewController.
The Second document on is on how to subclass UIView's in general. Defiantly worth the read. Since you said you're a beginner, it's probably best to use Auto-Layout, so you should probably start there.