1

この独特の問題について助けが必要です。多肢選択式の質問アプリがあり、UITextview として選択肢があります。場合によっては、選択肢 D が何らかの理由で半分にカットされることがあります。

スクリーンショット: 選択肢Dは半額!

ここで何が起こっているのかわかりません。私は基本的に UITextView フレームを contentSize に調整します。

                CGRect dFrame = choiceD.frame;
                dFrame.size.height = choiceD.contentSize.height;
                choiceD.frame = dFrame;

何か案は?前もって感謝します。

4

3 に答える 3

0

私の提案は、最初に次のようにtextViewに入力したテキストのサイズを計算することです。

      //Give the maximum size of label which that label can have.
CGSize maximumLabelSize = CGSizeMake(300,500);
CGSize expectedLabelSize = [Label.text sizeWithFont:Label.font constrainedToSize:maximumLabelSize lineBreakMode:UILineBreakModeWordWrap];

      //adjust the label the new height.
CGRect newDescFrame = Label.frame;
newLabelFrame.size.height = expectedLabelSize.height;
NSLog(@"%f",newLabelFrame.size.height);
      //adjust the label the new width.
newLabelFrame.size.width = expectedLabelSize.width;
NSLog(@"%f",newLabelFrame.size.width);
      //Set the label size according to the new height and width.
label.frame = newLabelFrame;

textViewにテキストを入力した後、上記のコードを記述します。お役に立てば幸いです。ありがとうございます:)

于 2012-04-17T04:57:43.047 に答える
0

Caculate the size of string:

    NSString *choiceDString = @"Equal the present value....";
    CGSize size = [choiceDString sizeWithFont:[UIFont systemFontOfSize:CHOICE_FONT_SIZE] constrainedToSize:CGSizeMake(CHOICE_WIDTH, 100000)];

Init a label to content the choice string:

    UILabel *choiceDLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,0,size.width,size.height)];
    choiceDLabel.text= choiceDString;

Add the subview label for button:

    [button addSubview:choiceLabel];
于 2012-04-17T03:10:49.500 に答える
0

このコードを使用してください..テキストの長さに応じてラベルの高さを定義しています...

NSString *summary;
summary = @" your text";
CGSize sizeofbuttonorlable = [summary sizeWithFont:[UIFont systemFontOfSize:30] 
               constrainedToSize:CGSizeMake(self.view.bounds.size.width - 40, MAXFLOAT)  
                   lineBreakMode:UILineBreakModeWordWrap];

CGRect frame = CGRectMake(0.0f, 0.0f, 320.0f, sizeofbuttonorlable.height);
UILabel *choiceDLabel = [[UILabel alloc] initWithFrame:frame];
choiceDLabel.text= summary;
[button addSubview:choiceLabel];

うまくいけば、これはあなたを助けるでしょう...寒さ

于 2012-04-17T03:16:55.373 に答える