The effect is as follows:
ViewController.h
1 #import <UIKit/UIKit.h>23@interface viewcontroller: Uiviewcontroller4 @property (Strong, Nonatomic) UILabel *lblmessage; 5 6 @end
Viewcontroller.m
1 #import "ViewController.h"2 3 @interfaceViewcontroller ()4 @end5 6 @implementationViewcontroller7 8- (void) Viewdidload {9 [Super Viewdidload];Ten OneSelf.title =@"LineBreak"; ASelf.view.backgroundColor =[Uicolor Blackcolor]; - -_lblmessage = [[UILabel alloc] Initwithframe:cgrectmake ( -, -, the,460)]; the_lblmessage.text =@"Click on the screen to set the text line break and omit mode; Something you can try to do."; -_lblmessage.textcolor = [Uicolor colorwithred:0.335Green0.915Blue1.000Alpha1.000]; -_lblmessage.textalignment =Nstextalignmentleft; -_lblmessage.backgroundcolor = [Uicolor colorwithred:0.852Green0.941Blue1.000Alpha1.000]; +_lblmessage.linebreakmode = Nslinebreakbytruncatingtail;//The default value is Nslinebreakbytruncatingtail, and the trailer is truncated . - [Self.view addsubview:_lblmessage]; + } A at- (void) didreceivememorywarning { - [Super didreceivememorywarning]; - //Dispose of any resources the can be recreated. - } - - #pragmaMark-private Methods in- (void) touchesended: (Nsset *) touches withevent: (Uievent *)Event { - StaticNsuinteger i =1; to Switch(i%6) { + Case 0: -_lblmessage.linebreakmode = Nslinebreakbytruncatingtail;//truncated trailing ellipsis mode; default value the_lblmessage.text =@"Nslinebreakbytruncatingtail;something can try to do."; * Break; $ Case 1:Panax Notoginseng_lblmessage.linebreakmode = Nslinebreakbytruncatinghead;//cut off the head ellipsis mode -_lblmessage.text =@"Nslinebreakbytruncatinghead;something can try to do."; the Break; + Case 2: A_lblmessage.linebreakmode = Nslinebreakbytruncatingmiddle;//cut off intermediate ellipsis mode the_lblmessage.text =@"Nslinebreakbytruncatingtail;something can try to do."; + Break; - Case 3: $_lblmessage.linebreakmode = nslinebreakbyclipping;//cut off the tail. $_lblmessage.text =@"Nslinebreakbyclipping;something can try to do."; - Break; - Case 4: the_lblmessage.linebreakmode = nslinebreakbycharwrapping;//cut off the tail in the form of a character split -_lblmessage.text =@"Nslinebreakbycharwrapping;something can try to do.";Wuyi Break; the Case 5: -_lblmessage.linebreakmode = nslinebreakbywordwrapping;//cut off the tail with a word (half character) split Wu_lblmessage.text =@"Nslinebreakbywordwrapping;something can try to do."; - Break; About } $i++; - } - - @end
047 set text line wrapping and ellipsis modes