答案 0 :(得分:0)
我认为你会在here中找到关于这个主题的很多有用的信息
所以你需要使用CoreText来实现你的目标。
答案 1 :(得分:0)
试试这个
请注意,仅适用于TextView
NSString *myTextString =@"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
答案 2 :(得分:0)
这是我在操场上实施的( Swift 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
<强>输出:强>
答案 3 :(得分:0)
@ {KKRocks Swift 3.0
中的answer
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)