//定义Container NSTextContainer * container = [[NSTextContainer alloc]initWithSize:CGSizeMake(150, 200)]; //定义布局管理类 NSLayoutManager * layoutManager = [[NSLayoutManager alloc]init]; //将container添加进布局管理类管理 [layoutManager addTextContainer:container]; //定义一个Storage NSTextStorage * storage = [[NSTextStorage alloc]initWithString:@"The NSTextContainer class defines a region where text is laid out. An NSLayoutManager uses NSTextContainer to determine where to break lines, lay out portions of text, and so on."]; //为Storage添加一个布局管理器 [storage addLayoutManager:layoutManager]; //将要显示的container与视图TextView绑定 UITextView * textView = [[UITextView alloc]initWithFrame:self.view.frame textContainer:container]; [self.view addSubview:textView];
UIBezierPath * path = [UIBezierPath bezierPathWithArcCenter:self.view.center radius:70 startAngle:0 endAngle:M_PI*2 clockwise:YES]; container.exclusionPaths = @[path]; container.lineBreakMode = NSLineBreakByCharWrapping; NSLayoutManager * layoutManager = [[NSLayoutManager alloc]init]; [layoutManager addTextContainer:container]; NSTextStorage * storage = [[NSTextStorage alloc]initWithString:@"The NSTextContainer class defines a region where text is laid out. An NSLayoutManager uses NSTextContainer to determine where to break lines, lay out portions of text, and so on. An NSTextContainer object normally defines rectangular regions, but you can define exclusion paths inside the text container to create regions where text does not flow. You can also subclass to create text containers with nonrectangular regions, such as circular regions, regions with holes in them, or regions that flow alongside graphics.The NSTextContainer class defines a region where text is laid out. An NSLayoutManager uses NSTextContainer to determine where to break lines, lay out portions of text, and so on. An NSTextContainer object normally defines rectangular regions, but you can define exclusion paths inside the text container to create regions where text does not flow. You can also subclass to create text containers with nonrectangular regions, such as circular regions, regions with holes in them, or regions that flow alongside graphics.An NSLayoutManager uses NSTextContainer to determine where to break lines, lay out portions of text, and so on. An NSTextContainer object normally defines rectangular regions, but you can define exclusion paths inside the text container to create regions where text does not flow. You can also subclass to create text containers with nonrectangular regions, such as circular regions, regions with holes in them, or regions that flow alongside graphics."]; [storage addLayoutManager:layoutManager]; UITextView * textView = [[UITextView alloc]initWithFrame:self.view.frame textContainer:container]; [self.view addSubview:textView];