8

私はテキスト(本の物語)を持っています。私はそれを表示するために UILabel を取っています。しかし、それは私を表示していません。次のコードを使用しています。

    CGSize labelsize;
    UILabel *commentsTextLabel = [[UILabel alloc] init];;
    [commentsTextLabel setNumberOfLines:0];
    commentsTextLabel.textColor = [UIColor blackColor];
    [commentsTextLabel setBackgroundColor:[UIColor clearColor]];
    [commentsTextLabel setFont:[UIFont fontWithName:@"ACaslonPro-Regular"size:17]];
    labelsize=[story sizeWithFont:commentsTextLabel.font constrainedToSize:CGSizeMake(280, 15000) lineBreakMode:NSLineBreakByWordWrapping];
    commentsTextLabel.frame=CGRectMake(20, 200, 280, labelsize.height);
   commentsTextLabel.text = story;// more than 1000 lines

   [self.view addSubview:commentsTextLabel];

コードをデバッグすると、13145 の場合、labelsize.height が出てくることがわかりました。それでも表示されません。15000 を 11000 に減らすと、テキストがビューに表示されて .... ついに。

labelsize=[story sizeWithFont:commentsTextLabel.font constraintToSize:CGSizeMake(280, 15000) lineBreakMode:NSLineBreakByWordWrapping];

私を助けてください。ありがとう

4

6 に答える 6

2

私は最近同じことを経験しました.UILabelのサイズが正しく割り当てられています.UILabel自体があまりにも多くの文字を保持できないだけです.最大文字制限はフォントとフォントサイズによって異なります.

私が使用したフォントの場合、制限は約 13k 文字です。私の回避策は、事前に文字列を切り捨てることですが、理想的ではありません。

于 2013-07-19T00:33:39.030 に答える