2017-06-20 39 views

回答

0

我認爲你會在here找到很多有用的信息的有關此主題的

所以你需要使用CoreText來實現自己的目標。

+0

不幸的是在這個環節GitHub的例子是不完整的。但我想我有一個方向來實現它,因爲我需要學習CoreText框架的一些核心概念。如果你已經有CoreText框架的經驗,你能給我一個工作的例子嗎?謝謝 – iMemon

+0

不幸的是我對CoreText沒有太多的瞭解。但我認爲你可以檢查其他人如何使用它,在這裏你有一堆開源項目:https://www.cocoacontrols.com/search?q=coretext – Robert

0

試試這個

注意僅此爲TextView的

 NSString *myTextString [email protected]"Your are qualified as a lawyer specializing in marine cases, shipping, arbitration and commercial litigation"; 
     UIBezierPath * imgRect = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, 40, 40)]; // you can change this as per your needs 
     txtViewDescription.textContainer.exclusionPaths = @[imgRect]; 
     txtViewDescription.text = myTextString; 
     txtViewDescription.text = [txtViewDescription.text substringFromIndex:1]; // Remove first letter from string 

     UILabel *lbl = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 80, 80)];// you can change this as per your needs 
     lbl.font = [UIFont fontWithName:Lato_BOLD size:50]; 
     lbl.text = [myTextString substringToIndex: 1]; // get first letter of string 
     [self.view bringSubviewToFront:lbl]; 
     [self.view addSubview:lbl];// if your textview added to self.view else change with your view 
0

這是我在操場實施(斯威夫特3回答):

import UIKit 

// declare the label: 
let label = UILabel(frame: CGRect(x: 0, y: 0, width: 300, height: 300)) 
label.numberOfLines = 2 
label.backgroundColor = UIColor.white 

// this should be the desired text 
let myString = "This is my pretty string that should contains a couple of lines." 

// setup the attributed string 
let content = NSMutableAttributedString(string: myString, attributes: [NSFontAttributeName: UIFont.systemFont(ofSize: 20)]) 
content.setAttributes([NSFontAttributeName: UIFont.systemFont(ofSize: 40), NSForegroundColorAttributeName: UIColor.red], range: NSRange(location: 0, length: 1)) 

// assign the string to the label 
label.attributedText = content 

輸出:

enter image description here

0

@ KKRocks的answerSwift 3.0

let yourString = "This easy granola is inspired by a grain-free granola from Costco that I love. The ingredient list is short so I figured that I could make it at home quite easily." 



    let lbl = UILabel(frame: CGRect(x: 5, y: 5, width: 30, height: 30)) 
    lbl.font = UIFont.boldSystemFont(ofSize: 40) 
    lbl.text = yourString[0] 
    txtView.addSubview(lbl) 
    txtView.bringSubview(toFront: lbl) 

    let bezierPath = UIBezierPath(rect: CGRect(x: 0, y: 0, width: 35, height: 30)) 
    txtView.textContainer.exclusionPaths = [bezierPath] 
    txtView.text = yourString.substring(from: 1) 
    // txtView.textContainerInset = UIEdgeInsetsMake(10, 10, 10, 10) 
相關問題