How to customize UILabel or UITextView like given image i-e big "T" is shown in two lines of the label. Or please suggest any library for that:
Asked
Active
Viewed 871 times
4 Answers
0
I think that you will find in here a lot of useful informations about this topic
So you need use CoreText to achieve your goal.

Robert
- 3,790
- 1
- 27
- 46
-
Unfortunately the github example in this link is incomplete. But I guess I got a direction to achieve it, for that i need to learn some core concepts of CoreText framework. Can you send me a working example if you already have experience with CoreText framework ? Thanks – iMemon Jun 20 '17 at 08:21
-
unfortunately I don't have great knowledge about CoreText. But I think that you can check how other use it, here you have bunch of open source projects: https://www.cocoacontrols.com/search?q=coretext – Robert Jun 20 '17 at 08:55
0
Try this
Note this only for 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

KKRocks
- 8,222
- 1
- 18
- 84
0
This is what I implemented on a playground (Swift 3 answer):
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
Output:

Ahmad F
- 30,560
- 17
- 97
- 143
0
@KKRocks's answer in 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)

MilanPanchal
- 2,943
- 1
- 19
- 37