2013-04-22 55 views
0

有一些文本框显示给定的行数,当用户点击更多的应用程序时,它展开并显示其余的部分, 我熟悉代码来扩大我的UITextView但不知道如何添加“更多...”,然后“少......”,当用户点击“更多...”时扩展文本视图

选项it

微调的问题:我不是希望添加一个按钮,但是当文本大于控件的大小时,默认的IOS行为将会放在......末尾或中间,例如:这是...或者是...长

回答

0

你可以拿一个按钮并添加该UIButton在UITextView下面查看,当你点击该按钮时,改变与UITextView相关的按钮位置和标题。

0

您可以实现,使用方法(sizeWithFont:constrainedToSize:lineBreakMode :)

首先取出你需要显示成这样

NSString *textToBeShown = @"jhfsdg djsgf jdsfsdf dsf"; 
CGSize textSize = [textToBeShown sizeWithFont:[UIFont fontWithName:@"Arial-BoldMT" size:11]] 
           constrainedToSize:CGSizeMake(constrainedWidth,constrainedHeight) 
            lineBreakMode:NSLineBreakByWordWrapping]; 

的文本字段的文本的大小假设你想你的在按下“ShowMore”按钮之前,textview高度为100.0,然后您可以检查textSize.height与100.0相比,如果textHeight小于100.0,则将TextView的Heigth指定为textSize.height,否则将其指定为100.0像素。 现在,当单击show more按钮时,将textSize.height指定为用于显示文本的UITextView的高度。

NSString *textToBeShown = @"jhfsdg djsgf jdsfsdf dsf"; 
CGSize textSize = [textToBeShown sizeWithFont:[UIFont fontWithName:@"Arial-BoldMT" size:11]] 
          constrainedToSize:CGSizeMake(constrainedWidth,constrainedHeight) 
           lineBreakMode:NSLineBreakByWordWrapping]; 

textView.frame=CGRectMale(textView.frame.origin.x, 
          textView.frame.origin.y, 
          textSize.width, 
          textSize.height);