2
A
回答
0
我認爲你會在here找到很多有用的信息的有關此主題的
所以你需要使用CoreText來實現自己的目標。
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
輸出:
0
@ KKRocks的answer在Swift 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)
相關問題
- 1. 更改一行UITextView的字體大小?
- 2. 更改字母第一個字母的字體顏色
- 3. 將兩個單詞中的第一個字母大寫爲兩個字符串
- 4. Swift大寫字母中每個單詞的第一個字母
- 5. java中兩個字符串的大寫字母的常見字符/字母
- 6. 在第一個非字母字符分割字符串
- 7. 與兩個字母
- 8. iOS - 在UILabel或UITextView中動畫改變文字大小?
- 9. 大寫字母中的第一個字母?
- 10. EditText的第一個字母大寫字母
- 11. MIPS丟棄大寫字母或非字母數字
- 12. preg_match:字符串和第一個非字母數字字符
- 13. 對字符串進行排序,第一個字母第一個,然後是字母內部的字母
- 14. 如何在字符串中使用Javascirpt大寫字母的第一個字母
- 15. BASH - 讓第一個字母大寫
- 16. 第一個字母大寫小寫
- 17. 尋找第一個大寫字母
- 18. 如何使用python在字符串中查找第一個非大寫字母
- 19. 用紅寶石字母大寫第一個字母
- 20. 大寫字母冒號後跟第一個字母?:Javascript
- 21. 如何獲得UILabel(UITextView)自動調整字體大小?
- 22. 將UIView或UILabel放置在UITextField或UITextView中,就像字符一樣行動
- 23. TextBlock與大寫字母一樣大(忽略字體ascender/descender)
- 24. 當第一個字符是數字時更改爲第一個大寫字母
- 25. 第一個字母的大寫的EditText與GBoard輸入
- 26. 大寫字母中的三個字母單詞的第一個和最後一個字母
- 27. 如何分割或與第一個非字母數字字符爆炸字符串 - PHP
- 28. 使用PHP將每行的第一個字母大寫PHP
- 29. 將文件中每行的第一個字母改爲大寫
- 30. 在sql中是否有任何函數可能返回前兩個字母或第一個字母的結果?
不幸的是在這個環節GitHub的例子是不完整的。但我想我有一個方向來實現它,因爲我需要學習CoreText框架的一些核心概念。如果你已經有CoreText框架的經驗,你能給我一個工作的例子嗎?謝謝 – iMemon
不幸的是我對CoreText沒有太多的瞭解。但我認爲你可以檢查其他人如何使用它,在這裏你有一堆開源項目:https://www.cocoacontrols.com/search?q=coretext – Robert