我在分页滚动视图中有一系列uitextviews.我想让每个页面内的文本在一个倾斜的矩形(平行四边形)内流动.图像附加(我希望文本在白色轮廓内流动).

代码如下.
for (int i = 0; i < imageArray.count; i++) {
CGRect framee;
framee.origin.x = self.uis_scrollView.frame.size.width * i;
framee.origin.y = 0;
framee.size = self.uis_scrollView.frame.size;
UITextView *newTextView = [[UITextView alloc] initWithFrame:framee];
UIBezierPath* rectanglePath = [UIBezierPath bezierPath];
[rectanglePath moveToPoint: CGPointMake(652, 687)];
[rectanglePath addLineToPoint: CGPointMake(680, 687)];
[rectanglePath addLineToPoint: CGPointMake(746, 541)];
[rectanglePath addLineToPoint: CGPointMake(718, 541)];
[rectanglePath addLineToPoint: CGPointMake(652, 687)];
[rectanglePath closePath];
UIBezierPath * imgRect = rectanglePath;
newTextView.textContainer.exclusionPaths = @[imgRect];
[newTextView setBackgroundColor:[UIColor clearColor]];
[newTextView setTextColor:[UIColor whiteColor]];
[newTextView setFont:[UIFont systemFontOfSize:16]];
newTextView.text = [imageArray objectAtIndex:i];
newTextView.userInteractionEnabled = NO;
[_uis_scrollView addSubview:newTextView];
}
Run Code Online (Sandbox Code Playgroud)
也许它只是为了流动?也许我需要在右侧'画'一个倾斜的矩形,这将限制内容?
排除路径的目的实际上只是使文本围绕它流动.您应该创建一个或多个排除路径,覆盖您不希望看到任何文本的三角形区域.请记住,这些路径必须在坐标系中UITextView.如果我有一个大小的textview,{320,218}我想在右边切出一个三角形部分,代码将如下所示:
UIBezierPath* path = [UIBezierPath bezierPath];
[path moveToPoint: CGPointMake(320, 0)];
[path addLineToPoint: CGPointMake(320, 218)];
[path addLineToPoint: CGPointMake(210, 0)];
[path closePath];
self.textView.textContainer.exclusionPaths = @[path];
Run Code Online (Sandbox Code Playgroud)
结果如下:

您的问题是您想要从每个 textView中减去超视图坐标系中的矩形.据我所知,没有用a 创建任意交点的方法,因此你必须为每个textView手动计算几个三角形的坐标.UIBezierPathCGRectUIBezierPath
为简单起见,您可以计算三角形排除路径的斜边与textView的rect之间的交点.这是一个风格化的屏幕图片,向左旋转90度:

| 归档时间: |
|
| 查看次数: |
362 次 |
| 最近记录: |