我需要帮助来解决这个特殊的问题。我有一个多项选择题应用程序,我有作为UITextview的选择。有时,选择D会因为某种原因被一分为二。
截图:

不知道这是怎么回事。基本上,我让UITextView框架调整为它的contentSize。
CGRect dFrame = choiceD.frame;
dFrame.size.height = choiceD.contentSize.height;
choiceD.frame = dFrame;有什么想法吗?提前谢谢。
发布于 2012-04-17 11:10:50
计算字符串的大小:
NSString *choiceDString = @"Equal the present value....";
CGSize size = [choiceDString sizeWithFont:[UIFont systemFontOfSize:CHOICE_FONT_SIZE] constrainedToSize:CGSizeMake(CHOICE_WIDTH, 100000)];初始化一个标签以包含选项字符串:
UILabel *choiceDLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,0,size.width,size.height)];
choiceDLabel.text= choiceDString;添加按钮的子视图标签:
[button addSubview:choiceLabel];发布于 2012-04-17 11:16:55
使用此code..Yo可根据您的文本长度定义标签的高度...
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];希望这能帮助you...chill
发布于 2012-04-17 12:57:43
我的建议是首先计算您在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中输入文本后编写上述代码。希望是helps.Thanks :)
https://stackoverflow.com/questions/10184495
复制相似问题