0

UILabel で複数行を表示する必要があります (テキストが大きい場合)。以下は私のコードです。iOS のバージョンごとに個別のプロパティを使用しています。私を助けてください..

    labelLocation.numberOfLines=2;
    labelLocation.font=[UIFont systemFontOfSize:25];
    if ([[[UIDevice currentDevice]systemVersion]floatValue]>=6) {
        labelLocation.lineBreakMode=NSLineBreakByTruncatingTail;
        labelLocation.minimumScaleFactor=10.0/[UIFont labelFontSize];
    }else{
        labelLocation.lineBreakMode=UILineBreakModeTailTruncation;
        labelLocation.minimumFontSize=10;
    }
    labelLocation.text=@"Can we make UILabeltext in 2 lines if name is large";
4

6 に答える 6

3

これらの 2 つの行が一緒に機能します

labelLocation.numberOfLines=0;
labelLocation.lineBreakMode = NSLineBreakByWordWrapping;
于 2013-08-13T11:14:35.933 に答える
0

個人的には、テキストを表示するために必要な高さを計算してからラベルに表示することをお勧めします。UITextView や UILable などのテキスト表示コンポーネントをハードコーディングしないでください。

 NSString *str = @"This is to test the lable for the auto increment of height. This is only a test. The real data is something different.";


`UIFont * myFont = [UIFont fontWithName:@"Arial" size:12];//specify your font details here
//then calculate the required height for the above text.

CGSize lableSiZE = [str sizeWithFont:myFont constrainedToSize:CGSizeMake(240, CGFLOAT_MAX) lineBreakMode:NSLineBreakByWordWrapping];

//上記で取得した高さに基づいてラベルを初期化します。好きな幅を設定できます...

 UILabel *myLable = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, lableSiZE.width, lableSiZE.height)];

myLable.text = str;
myLable.numberOfLines=0;
myLable.font=[UIFont fontWithName:@"Arial" size:12];
//myLable.backgroundColor=[UIColor redColor];
myLable.lineBreakMode = NSLineBreakByWordWrapping;
于 2013-08-13T11:45:17.283 に答える
0

あなたのコードをこれに変更してください

labelLocation.numberOfLines=0;
labelLocation.font=[UIFont systemFontOfSize:40];
labelLocation.lineBreakMode=NSLineBreakModeWordWrap;
labelLocation.text=@"Can we make UILabeltext in 2 lines if name is large";
于 2013-08-13T11:44:10.533 に答える