2014-01-06 57 views
3

我在分頁滾動視圖中有一系列uitextviews。我希望每個頁面中的文本在傾斜的矩形(平行四邊形)內流動。附圖(我希望文字在白色輪廓內流動)。下面平行四邊形形狀內的流uitextview(iOS7)

white outline is the flow shape needed

代碼。

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]; 
    } 

也許它只是爲了四處流動?也許我需要在右側畫一個傾斜的矩形來限制內容?

回答

6

排除路徑的目的實際上只是使文本圍繞它流動。您應該創建一個或多個排除路徑,以覆蓋您不想看到任何文本的三角形區域。請記住,這些路徑必須在UITextView的座標系中爲。如果我有大小{320,218}一個TextView,我想切出右側的三角形部分,代碼應該是這樣的:

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]; 

,結果是這樣的:

screenshot of excluded triangle textview

你的問題是你想要減去超級瀏覽器座標系中的矩形每個 textView。據我所知,沒有辦法創建任意UIBezierPathCGRect的交點,所以您將不得不爲每個textView手動計算幾個UIBezierPath三角形的座標。

爲了簡單起見,您可以計算三角形排除路徑的斜邊和textView的矩形之間的交點。這是你的屏幕的程式化的圖片,旋轉90度向左:

geometry

+0

完美的解釋 - 謝謝! – malaki1974