Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set dots at the end of UIButton if title is long

I have a UIButton, I want to set title for it with a long text. e.g: @"set dots at the end of UIButton if title is long"

I used:

[btn setTitle:@"set dots at the end of UIButton if title is long" forState:UIControlStateNormal];

--> btn appear as: "set dots...at the"

Now I want to show "set dots at the..."

How I can do?

Thanks All!

like image 726
Bkillnest Avatar asked Feb 10 '15 03:02

Bkillnest


2 Answers

Surprisingly, there is no existing post about this for a button label.

Simply do:

[btn setTitle:@"set dots at the end of UIButton if title is long" forState:UIControlStateNormal];
btn.titleLabel.lineBreakMode = NSLineBreakByTruncatingTail;

Accessing the button's titleLabel lets you adjust the button's label attributes as needed when a direct UIButton method doesn't exist.

like image 91
rmaddy Avatar answered Oct 22 '22 21:10

rmaddy


In storyboard after select button go to attribute inspector and set lineBreak property to Truncate Tail.

.enter image description here

like image 35
vikrant tanwar Avatar answered Oct 22 '22 22:10

vikrant tanwar