I need your help for a (maybe?) stupid question.
I'm new to Swift and I still have to understand a couple of things in Xcode.
One of these is TEXT ALIGNMENT.
I want to align a label to an imageview just like the picture I have attached.
Can someone please help me undertsand how can I do it?
Is it just a matter of constraints or is there something else I have to do via code?
Thank you in advance.
I'd like to achieve this in Xcode
In the Attributes Inspector of Interface Builder, on the Label, set the Lines property to 0. This will act like text wrap. You don't have to do anything to align it except manually drag the label next to the image view.
you can do with constraint
for image set leading and top constraint and make Top Base alignment to Label and Image by select to Item check this image
Related
When I add a UITextView and I fill it with words, then I go to Attribute inspector and set its text Alignment to Left by clicking the first option as you can see in the picture below. It works properly but if I try to align the text to center or I try to set its alignment as Justify as shown in the picture below, it gives me an error.
Does anyone know why?
Picture
I have a basic UIViewController with a UILabel that I want to populate dynamically at runtime. I want the elements surrounding the UILabel to move as the UILabel expands. I have constraints added that should allow for this, but I haven't been able to test it because my lines don't wrap on the Label like they should. I have set the Number of Lines in the Attributes Inspector to 0 and changed the Line Break mode to Word Wrap. However, the UILabel box won't expand in height to account for the amount of text. How can I go about setting this up? Thank you!!
Your Constraints are not created right.
I would suggest you create a new project and start with two labels to get a better understanding of how autolayout works.
Try deleting your Height-Constraint.
Autolayout will think that it needs to maintain the Height of 21 in your case.
If you delete it or set it with a low priority it should work.
I recreated your sample and got it working:
I've been trying to learn about autolayouts in xcode 5 by watching some youtube videos. On the videos, they say:
switch on autolayout (which I've done)
Then while dragging an object around the storyboard you'll see blue guides (which I do).
Then, when letting go mouse the mouse, a constraint which look like the letter 'I' appears.
However, this doesn't happen for me - it's like constraints aren't being added?
Am I doing something wrong? Hope this isn't too vague!
Shell
After you place a View inside Interface Builder and blue lines did appear,
click on the Resolve auto layout issues button (second to last button in the bottom right corner; looks like circle between vertical lines)
select the Add missing constraints option
The constraints that were "proposed" by by the blue lines should now be automatically added to the view.
Xcode 4 added constraints automatically.
Xcode 5 only adds constraints if you tell it to.
To add constraints in Xcode 5 you need to explicitly lay them out.
You are only one step away...
Turn on auto layout.
Add you element to the view. You will see the blue guidelines.
Add your constraints by holding down CTRL and clicking from the element you added to the one you wish to add a constraint between.
e.g. If you want to add a constraint for the width of the element. CTRL-drag from the elements back to itself.
If you want to add a space constraint to the superview then CTRL-drag from the element to its superview in the direction you want to add the constraint.
If you want to add a space constraint between two elements. CTRL-drag from one element to the other.
I cannot find how to a text field group, similar to what is in the Address Book app:
(source: puc.edu)
Can someone tell me what I am doing wrong? I can't find an option to make them look this way.
Also, does anyone know the font, font size and color?
As Devin mentioned it is just a UITableView with it's style set to Grouped. Then each cell contains a UITextField. They probably also worked their magic so when you click "Next" in the first cell, it automatically assigns the second cell as a first responder, which then moves the cursor down instead of putting the keyboard away.
This is a Table with the style set to "grouped".
Here's a reference: http://developer.apple.com/iphone/library/documentation/UserExperience/Conceptual/TableView_iPhone/AboutTableViewsiPhone/AboutTableViewsiPhone.html
I'm working on a iPhone product page where some of the fields can be fairly long (product name etc.) I've created the page layout in IB, and use UILabels to show the text fields. For those long text labels I'd like the height of the label to scale and push the other labels further down. Is this possible using IB, or would I have to do everything in code? (Compute height and position of all the UILabels.)
I'm presently able to get the text in the labels to wrap and fill the available space, but I have to reserve space for this. When the label is only one line it leaves lots of unused space before the next label.
You will have to calculate the heights dynamically in code. I'm not sure what you're doing exactly, but you may want to start using a UITableView and return variable height cells. I wrote a blog post on how to do this at Cocoa Is My Girlfriend.
It did some searching for this same thing and as far as I can tell you have to manually resize and position the labels.
If you want to know how to dynamically resize a label, this is how I am doing it:
myLabel.frame = CGRectMake(227.0, 12.0, 22.0, 21.0);
I am happy to be wrong on this one, since I don't like having to do this either.