UITextView 和UILable 它本身是没有控制行高的。很多人说用Uiwebview,但我觉得那不好用,要用html布局麻烦,占内存。也有人说drawatpoint,但
发现画中文的时候也很占内存,我就投机取巧一下吧
UILable 跟下面的用法一样的自己改一下
// DrawAtPoint // // Created by xia kejie on 12-5-13. // Copyright (c) 2012年 __MyCompanyName__. All rights reserved. // #import "ViewController.h" #define LINENUM 20 //每行字数 #define LINEHEIGHT 30 //行高 @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { int begin=0; NSString *partialString; [super viewDidLoad]; NSString* str=@"东南形胜,三吴都会,钱塘自古繁华。烟柳画桥,风帘翠幕,参差十万人家。云树 绕堤沙,怒涛卷霜雪,天堑无涯。市列珠玑,户盈罗绮,竞豪奢。重湖叠清嘉,有三秋桂子,十里荷花。羌管弄晴,菱歌泛夜,嬉嬉钓叟莲娃。千骑拥高衙,乘醉听箫鼓,吟赏烟霞。异日图将好景,归去凤池夸。云树 绕堤沙,怒涛卷霜雪,天堑无涯。市列珠玑,户盈罗绮,竞豪奢。重湖叠清嘉,有三秋桂子,十里荷花。羌管弄晴,菱歌泛夜,嬉嬉钓叟莲娃。千骑拥高衙,乘醉听箫鼓,吟赏烟霞。异日图将好景,归去凤池夸。"; int num = str.length/LINENUM; NSLog(@"%d",str.length); NSLog(@"%d",num); for (int i=0; i<=num; i++) { UITextView* textview=[[UITextView alloc]init]; NSLog(@"%d-----",begin); if(i==num) partialString=[str substringWithRange:NSMakeRange(begin,str.length%LINENUM)]; else partialString=[str substringWithRange:NSMakeRange(begin,LINENUM)]; textview.backgroundColor=[UIColor clearColor]; textview.text=partialString; textview.frame=CGRectMake(0, 30+i*LINEHEIGHT, 300, 30); [self.view addSubview:textview]; begin+=LINENUM; NSLog(@"%@",partialString); } // Do any additional setup after loading the view, typically from a nib. }
下载:http://download.csdn.net/detail/x1135768777/4299088