Sunday, December 29, 2013

Label text wrapping problem

I'm doing an application, you need to use a Label to display more text will appear incomplete end of the line is displayed as "..." The situation is omitted. Due to limited demand and Label width font size, I would like to ask how to wrap the Label in effect?
Reply:
For a control is not on the list
Reply:
UIlabel there have attributes

The maximum number of lines to use for rendering text.

@ Property (nonatomic) NSInteger numberOfLines

This stuff is the label to tell how many rows.


Reply:
Then the property can be set to 0, then is to allow themselves to adapt.

Give size

CGSize sz = CGSizeMake (0, 0);
sz = [string sizeWithFont: [UIFont systemFontOfSize: 14]
constrainedToSize: sz
lineBreakMode: UILineBreakModeWordWrap];

Calculation of the string size

To the size of the label on it.
Reply:
Or ScrollView with TextView
Reply:
Or use UITextView it. UILabel suitable for displaying a small amount of text.
Reply:
NSString * str = @ "You have to put in the text for the label";
CGSize size = [str sizeOfFont: 14 constrainedToSize: CGSizeMake (width, 10000.0f) lineBreakMode: UILineBreakModeWordWrap];

UILabel * lb = [[UILabel alloc] initWithFrame: CGRectMake (x, y, width, height)];
lb.numberOfLine = 0;
lb.text = str;
lb.font = [UIFont systemFontOfSize: 14];
[Self.view addSubview: lb];
[Lb release];

Reply:
lb of frame to CGRectMake (x, y, width, size.height)

No comments:

Post a Comment