0
我對應該顯示1個隨機字符串的uilabel有點麻煩。有時整個字符串顯示沒有問題,但通常情況下,一些文本被切斷。這是我目前有:Objective-C:我的UILabel上的文本沒有正確包裝
// These are the 5 NSStrings which are placed in an array.
NSString *badOne = @"Bad? Your bill is nothing. I would consider that good service. SMDH.";
NSString *badTwo = @"You left out the amount dude.";
NSString *badThree = @"I can't tell you what the tip should be, if you don't tell me how much you dropped.";
NSString *badFour = @"Forgetting something?";
NSString *badFive = @"The tip should be over 9000... /n kidding.";
NSArray *badComments = [[NSArray alloc] initWithObjects:badOne, badTwo, badThree, badFour, badFive, nil];
// A random string is selected and assigned to badJoke.
int rand = arc4random()%5;
NSString *badJoke = [badComments objectAtIndex:rand];
// Here's the problematic code:
[_mainLabel setText:(badJoke)];
[_mainLabel setFrame:CGRectMake(50, 295, 200, 80)];
_mainLabel.adjustsFontSizeToFitWidth = NO;
_mainLabel.numberOfLines = 0;
[_amountTextField resignFirstResponder];
// This is a separate label, completely unrelated.
[_tipAmount setText:@""];
因此,舉例來說,一個時代可能出現「壞你的賬單沒有?」。 我也試過沒有setFrame線,沒有運氣。
任何幫助,將不勝感激。謝謝。
當你增加UILabel框架時發生了什麼?它在變化嗎?如果你可以張貼你得到的結果的一些截圖, – iDev
將會很有幫助 –