I don't know how to specify this kind of uilabel customisation but I want to add lines to the right and left side of the label and middle part will have the text. . I know one way is to take three labels i.e. left side label, right side label and centre text label but this approach seems to be inappropriate so suggest me a standard approach to do this programatically.
Related
I have a situation where a button title has two parts with different strings, and need to display one on the right and one on the left. Text will change dynamically every time based on response. I have to place this button in a tableview cell. Attaching an image below for reference.
The requirement is as follows:
.
But I managed to do the following:
I am unable to place text on two different sides of a button.
The easiest solution for you may be to place a UILabel on the left and anchor it to the left with a constraint, then place a UILabel on the right, and anchor it to the right with a constraint. - this is mentioned in the comments by #Alejandro Iván.
I would then choose a set value for the right label width and set that label. Add a constraint from the left label to the right label, so it will dynamically fill as much space as is available.
Last I would place a clear, no text button with the border on top, wrapping both labels. You can then confidently change the left label content and know that it will be encompassed in the button border.
Image attached to help you see what I'm saying although I've left the "button" text and added coloration to demonstrate.
I have a UILabel that covers most of the view. When I place text in the label, the text is center in the middle of the label. I have tried everything by playing around with the options in the attributes inspector, however the text wont start in the top area of the label, instead it appears in the middle of the label.
Is there any way to places the text in the top part of the label??
(If someones is wondering, yes I want the UILabel to cover most of the view because some texts are longer then others, and some are shorter, and I would prefer the text to be placed on the top part and not the middle of the UIlLabel.)
UILabel has an intrinsicContentSize matching the text contents. If you don't constrain the height, then it will automatically adjust. So you don't need to make it cover the entire view.
Instead, tag it onto the top with a fixed distance. Specify the bottom distance with greater-than-or-equal. This way the label can grow until it reaches the lower limit and then the text will begin to be truncated.
I'm creating an app with quite a lot of text. It will be of variable size, so I was wondering if there is a way to adapt my ScrollView to the size of the UILabel, not knowing in the IB what will be the number of lines of that label. I'm doing it from the IB, drag n dropping it, then I'm putting 4 elements inside : an image for the logo, a title, another image, and then the label.
My question is : how can I tell my ScrollView to adapt to the text ? With constraints ? In the code ? I'm sooooo lost with that scrolling thing…
I think I need a very very good tutorial about autolayout…
Here's some screenshots of my project
The project on simulator
The layout
Thanks a lot!
You have to add the constraints to your label so that it will always have the same spacing to the scroll view. Also, you will have to set your labels lines to 0.
Don't press Add Missing Constraints because it will probably set your height and you don't want that to happen. Use the Pin button to set the spacing to nearest neighbor.
These are the buttons you will have to use, they are bottom right.
First of all, press the one in the right and select All Views > Clear Constraints.
Then, select your label in the storyboard and press the button with a square Pin, here you will have to select everything until you have something like this with different values... Also click in the red lines so that you get a continuous red line. Don't check any of the boxes you see.
After this, you have to do the same process for your Scroller.
It should be enough. I will also need to know where your scroller is.
If you have anything else in your view, do the same.
How would I go about creating a layout like this using autolayout?
The icon is UIImage, text is UILabel.
The label text can vary in width, but will always be single-line. How do I force the label to scale with the text horizontally and UIImage to be immediately to the left of the label?
I have tried using attributedText. I also tried views as containers and a horizontal stack view, but failed to get the result I wanted. What are the other options?
That should be absolutely no problem - just put in the image, make layout constraints to the left and top of the view, then add the label right to it, and make layout constraints between the right side of the image and the left side of the text.
To restrict the label width you can add a constraint from the right side of the label to the right side of the view, if you want to make the label as small as possible with a greater-than sign.
EDIT
If the whole should be bound to the right border of the superview, put both in a view, align the view to the right border of the superview, and make a constraint from the right side of the label to the right side of the view. The view will resize accordingly when the label resizes.
I went for a solution where I added a third view as the leftmost element in a horizontal stackview and set the stackview's distribution as 'equal centering'. It actually fit well with the rest of the planned layout (all elements are used efficiently). Thank you for your help guys.
I am trying to learn to use layout constraints in interface builder but I am running across an issue...
I've got two views, one UILabel and one UIImageView, and I'd like a layout as follows:
the label should be centered in the superview
the imageview should be a set distance to the left of the label
Seems pretty simple, but I can't figure out how to impose a constraint for the second condition (the first is done automatically). Anyone know how to do this?
Thanks!
Click on both views while holding the command key so they're both highlighted. Then click on the pin button in the bottom right hand corner of IB (the middle button). Select horizontal spacing and the constraint should now be added. You should be able to adjust it as needed from there.