Label not displaying properly - ios

I am beginner in iOS app development, I am working on a project that was done by someone else. So my problem is the label is not fully showing its contents:
check the second column under 'customer name'.
I did some basic alterations to the label but it makes no change at all. This is a collection view, there is another view inside the collection view cell which holds the title label and description label.
I searched everywhere but didn't get any proper answer please help.

Label in iOS does not change its size to suit the contents, you need to adjust it in your code. Your options are either decrease the font size to suit the description label size, or adjust the description label's height/width to make room for current content. I'd do a combination of both (slightly reducing the font size of the label's text, and at the same time making all the cells a bit wider and taller).
Oh, there is also a way to automatically shrink the font size if the contents doesn't fit the space. So, you'd need to check the option for your description label. Here's how you might do it: how to make UILabel autosize text in storyboard (or interface builder), NOT programmatically

Related

how to set which label should be truncated if labels overlap?

i have a similiar problem as asked in How to resolve the Storyboard's warnings on Xcode?
However my left label can get really wide at runtime and the standard behaviour is, that the right label is truncated. How can i force the interface builder to truncate the left label and not the right one?
Both texts in the labels are set on runtime, so i have no knowledge of the resulting width of each label.
As stated above i used the solution from the linked question but the wrong label is truncated. So my problem differs from the one stated in the link.
There is a property called content compression resistance.
This determines how hard it resists compression of content.
So... for the label that you want to keep full length run this...
label.setContentCompressionResisyancePriority(.required, axis: .horizontal)
I’m typing on my phone so I may have messed up the parameter names. But auto complete will help.
This will make sure that the other label is truncated first.
You can also set this in IB in the measurements panel near the bottom.

Xcode Label with long Text not properly shown

This is my first IOS app, just for training, and I got some issue with Label ,check the image
As you can See Object: Photo- Visualizing the Thomas Walther is not properly shown and some words are missing.
So How to fix it and make the string appears on multiLines if it's too long?
In your storyboard, select the UILabel and open the Attributes Inspector (in the utilities, which can be opened with the shortcut opt-command-4). You can change all the the basic properties of the UILabel here.
For multiple lines, ensure that the label height is large enough and set the Lines to 0. You can also change the font scaling in the Autoshrink property (default is fixed font size).
I can't really tell from your screenshot, but you may have some Auto Layout issues with the width of your label to the right side of the window. So you may want to look into setting Auto Layout constraints as well.

UILabel that has unnecessary padding in a cell

I'm trying to make a Facebook clone for practicing iOS and I can't see why a label I have on my news feed gets unnecessary padding.
It only occurs on some labels, others on my news feed turn out fine. However for a select few there's a block of white pace above and below. At first I thought it was an alignment issue so I changed the labels background to green to show that the constraints hold out.
Anyone know as to why it's placing the padding, only for a select few?
By default UILabel will center its content vertically. Therefore, if label.bounds.size.height is greater than size of the text, the label's instinct is to center the content vertically, which will results in the vertical padding that you see in the attached image. Ensure that the label's height is being set according to the height of the text it contains and the problem should go away.
As dbart pointed out your label's frame is likely higher than the text needed. You can fix this by calling -sizeToFit. You can also check the amount of space the label is actually using for text by using +textRectWithBounds:maximumNumberOfLines:
If your cell is using autolayout to determine the height of the label you should set the preferredmaxlayoutwidth to an appropriate value (for example table width) before laying out the cell.

Multiline UILabel with auto layout does not work

I'm trying to set constraints to get a multiline label in a static table view cell, but apparently this does not work for me, the label is still in one single line. I've set the numberOfLines property to 0 and also the height constraint to greater than or equal. And I'm setting the height for the cell correctly in tableView:heightForRowAtIndexPath. Please have a look at my screenshot to see the settings in IB.
In the comments above you mentioned you're not currently setting preferredMaxLayoutWidth. This property tells your label that it should lay out its text over the width of that property's value. In UILabel.h:
If nonzero, this is used when determining -intrinsicContentSize for multiline labels
In other words, if you don't set that, the label's intrinsic content size is whatever width the label needs to draw its text. If you set this property to the label's bounds, it will start drawing on the next line (or else it will cut the text off if numberOfLines is 0).
In your case, I would probably do that in tableView:willDisplayCell:forRowAtIndexPath:.
You can set the preferredMaxLayoutWidth in code, but when designing your user interface in storyboard, you still see a long one-line label that gets cut off at the edges. An alternative is to manually insert line breaks anywhere in your text right within the storyboard using Option-Return. You then just set the number of lines to more than your text will fit. Then select your label, hit Cmd-=. This will calculate the intrinsic content size for your label with the line breaks exactly where you want them to be.
Theoretically, I think setting the preferredMaxLayoutWidth is the more correct way to go about this, especially using Autolayout. However, I found it more practical to use the method I described above because it lets you see the layout at design time right in the storyboard, and you have total control of your line breaks. This usually works better for labels with text that don't change often. If you are dynamically changing the label text, setting preferredMaxLayoutWidth is the preferred way.

Reposition images within view based on size of text - iOS

I have been recently getting into iOS development, and I'm trying to build something that looks (very roughly) like this: http://falkendev.com/downloads/ios-sample.png
Basically, it's a page that shows simple text -- large header text that may span multiple lines, a separator line, and then smaller descriptive text that may be a variable length. This text does not need to be editable. I'm working using interface builder, but I imagine that what I want done may need to be done programmatically?
Two questions:
-- How do I go about creating these text fields so that they adjust their height based on the content? I'm assuming I would be using a standard "text" field for each, make them not editable, and then programmatically change their height? And then based on the height of the various text fields, I would need to adjust the positioning of the text fields and the divider line between them?
-- How do I go about making the page scrollable? It's possible that the descriptive text will be long and would extend off the edge of the screen. I would want the whole page to be scrollable, not just the descriptive text section. I'm assuming I would place all my elements within a scroll view... but currently when I do that and view it, the view just gets centered (cutting off both the top and the bottom) and I can't scroll it at all.
Thanks for any help!
set the scrollview content size to greater than its actual size to
make it scrollable like this :
scrollView.contentSize = CGSizeMake(YourWidth ,YourHEight ); // Here you can change either of height and width to make it more scrollable in that direction.
You can use UITextView object to have a scrollable text field...
which can scroll to show additional text..just set its editing
property to NO.
Otherwise to dynamically update label height yourself...use
NSString sizeWithFont method

Resources