简体   繁体   中英

Changing Uilabel text style Objective-C

I search on google about how to change style of text in UILabel but I got nothing. My text is long and when I wrote a long text it displays " When will you ... for me? " but I want it displays " When will you go to market ... ". How can I do? Thank you for your kind.

you can do this in two ways

option -1

programmatically

Objective-C

label.lineBreakMode = NSLineBreakByTruncatingTail;

Swift

label.lineBreakMode =.byTruncatingTail

other types are

  // NSParagraphStyle
typedef NS_ENUM(NSInteger, NSLineBreakMode) {       /* What to do with long lines */
NSLineBreakByWordWrapping = 0,      /* Wrap at word boundaries, default */
NSLineBreakByCharWrapping,      /* Wrap at character boundaries */
NSLineBreakByClipping,      /* Simply clip */
NSLineBreakByTruncatingHead,    /* Truncate at head of line: "...wxyz" */
NSLineBreakByTruncatingTail,    /* Truncate at tail of line: "abcd..." */
NSLineBreakByTruncatingMiddle   /* Truncate middle of line:  "ab...yz" */
}

option -2

using storyboard attribute inspector

在此输入图像描述

You should set lineBreakMode property to your label to NSLineBreakByTruncatingTail . It will take care of that.

If your label in storyboard go to the property of label > Line Breaks choose Truncate Tail. If your adding it programmatically then add bellow code

yourLabel.lineBreakMode = NSLineBreakByTruncatingTail;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM