views:

44

answers:

2

Hi there,

New to posting here but got many really useful bits of help already.

I am shoving some text into a UIButton title ( UIButton setTitle: forState: ) I want only the first bit of the text to be displayed (ie only amount that fits). Currently, I am getting extra text spilling over into the view.

Is there any easy way to help stop the text from overflowing or do I have to implement my own word wrap algorithm to micromanage the amount of text I set the Title to?

A: 

iPhone SDK already implemented the algorithm and there are a number of options. There is a lineBreakMode property which you can use. You can use UILineBreakModeTailTruncation as the value. However, this property is Deprecated in iOS 3.0. You need to use titleLabel in OS 3.0

taskinoor
Hi Taskinoor, Not quite sure how this helps.... I can truncate the end of a line but I want lines to wrap until they get to the bottom of the button.
Tudor
u can set numberOfLines of titleLabel to more than one.
taskinoor
Basically titleLabel is an UILabel. So you can do everything that you can do with a normal label. Hope it helps.
taskinoor
Thanks. Problem solved.
Tudor
I was expecting a vote, at least :-)
taskinoor
A: 

Can't you set a maximum number of lines to the associated titleLabel ?

rano