objective c - How to tell when a UILabel will be truncated an/or its line break position will change -


itemprop = "text">

I have a multi-line UILabel ( numberOfLines = 0) . Its width can change on runtime, and sometimes it leads to spraying and / or re-rapping. In some instances, this is the best thing:

Example 1: Decrease in width Separate line leads to break points

Enter image details here Enter image details here

Example 2: Decrease width decrease Leads

Here's where Enter the details  Enter image details here

Example 3: The cut in width leads to both punching and a different line break position

 Enter image details here  Enter image details here

Example 4 : There is no effect on cutting or breaking position in width

 Here's the image Enter the file  Enter image details here

This change in formatting is quite confusing So, I intend to mask it behind some animation (possibly a fade / fade out). However, the first hurdle when I need to do this. Whenever the label is re-shaped I still do not want to apply on the animation - only when it will change the transition or line break situation.

How can I test it? Examples 1, 2, and 3 should be yes for example, but none for example.

Note: Changing the shape will never change the number of rows in my example.

Note 2: If anyone has some better tags related to text formatting, then I would love to know - feel free to edit Note 3: If you are interested in completing this behavior, then try Apple's Mail.app on the iPhone when an Inbox view is displayed on the iPhone and in the form of Fade-In / Outline Line It wraps again and / or trunkets clock (but it does not need when).

You can change the size of the label to display a specific NSString example Know For example, you can use that one:

- (CGSize) sizeWithFont: (UIFont *) font constrainedToSize: (CGSize) size lineBreakMode: (UILineBreakMode) lineBreakMode

returns the string size if it was sung with specified obstacles.

So what you want is to get CGSize for a particular string and check that it is not large, then UILabel Size:

  UILabel * label; CGSize sizeNeeded = [label.text sizeWithFont: label.font constrainedToSize: CGSizeMake (label.bounds.size.width, MAXFLOAT)]; If (sizeNeeded.height> gt; label.bounds.size.height) {NSLog (@ "string has been cut"); }   

More useful NSString methods you can find here:

OK, another way of doing whatever you want :

1) Create 2 UILabel with the same properties, but the second one ( label2 ) with another width Will happen.

2) Set alpha label2 to 0.0 in non-editing mode. 3) When editing mode starts making such an animation:

  // label1.alpha == 1.0, label2.alpha == 0.0 {[UIView animateWithDuration : 0.5 Animation: ^ {label1.alpha = 0.0; Label2.alpha = 1.0; }]; 4) When editing mode ends:  
  {[UIView animateWithDuration: 0.5 Animation: ^ {label1.alpha = 1.0; Label2.alpha = 0.0; }];   

This will give you similar results to Mail.app .

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -