UILabel alignment: show "..." at the end
In my app I am assigning fixed width a开发者_如何学编程nd height to uilabel and assigning some text to it. My problem is if the text length is more than the label height I want to show "..." at the end of the text eg "apple... " . Is there is any property to show like this?
Yes, please check the line break property and set it to truncateTail
label.lineBrakMode = UILineBreakModeTailTruncation;
Hope this helps,
CGSize maximumSize = CGSizeMake(300, 40); //to keep height fixed to 40 //or use (150,300) to keep width fixed to 150 and varying height .
NSString *myString =@"Text for lable";
UIFont *myFont = [UIFont fontWithName:@"marker felt" size:14];// font used for label
CGSize myStringSize = [myString sizeWithFont:myFont
constrainedToSize:maximumSize
lineBreakMode:label.lineBreakMode];
use MySTringSize to set the frame for label. And use nemberOfLines property for label, it might be helpfull.
精彩评论