2015-03-25 89 views
2

我正在使用Swift,設置在IB中創建的UITextView,嘗試在頁面上獲取多個圖像以編程方式來包裝文本。似乎與一個圖像路徑正常工作,但打破(停止包裝第一個圖像),當我添加第二個圖像。任何援助將不勝感激。Swift UITextView和UIImageView UIBezierPath

代碼示例:

override func viewDidLoad() { 
    super.viewDidLoad() 


    let image = UIImageView(image: UIImage(named: "testimage")) 
    image.frame = CGRect(x: 0, y: 0, width: 100, height: 100) 
    let path = UIBezierPath(rect: CGRectMake(0, 0, image.frame.width, image.frame.height)) 
    textContainer.textContainer.exclusionPaths = [path] 
    textContainer.addSubview(image) 

    let image2 = UIImageView(image: UIImage(named: "testimage2")) 
    image2.frame = CGRect(x: 100, y: 200, width: 100, height: 100) 
    let path2 = UIBezierPath(rect: CGRectMake(100, 200, image.frame.width, image.frame.height)) 
    textContainer.textContainer.exclusionPaths = [path2] 
    textContainer.addSubview(image2) 

謝謝!

多利安

回答

0

你需要第二路徑追加到exclusionPaths陣列。

目前您正在用第二個替換第一個路徑,而不是同時使用兩個。

例如:

textContainer.textContainer.exclusionPaths.append(path2)