Change the font style - (set Lable text in All-Caps format) to Objective C

I want to set the font style to UILable in Small-Caps format as shown below.

Please give me a solution for this if anyone knows

enter image description here

Thanks. :)

+6
source share
7 answers

If I'm not mistaken, is that what you want?

NSString *uppercaseString = [yourString uppercaseString]; 
+11
source

Fonts available on iOS do not have a "capitalistic style." You must add your own font or try to create a font using the CTFontDescriptorCreateCopyWithFeature function.
I think the easiest way would be to create an attribute string (NSAttributedString) with mixed font sizes.

+4
source

For iOS 7 custom fonts, the method is described by Anthony Mattox. For a system font, I don't know a way.

Font sets in small caches on iOS

+3
source

you can try with this

NSString * str = @ "mudit"; label.text = [str uppercaseString];

it will give you the output as follows: MUDIT

+1
source

To render UILabel as a string, where the first letter of each word is larger, you can do something like this:

 @implementation CapitalicTextLabel - (void)drawRect:(CGRect)rect { // Drawing code NSArray* words = [self.text componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetCharacterSpacing(context, 1); CGContextSetFillColorWithColor(context, [self.textColor CGColor]); CGAffineTransform myTextTransform = CGAffineTransformScale(CGAffineTransformIdentity, 1.f, -1.f ); CGContextSetTextMatrix (context, myTextTransform); CGFloat x = 0; float centeredY = (self.font.pointSize + (self.frame.size.height - self.font.pointSize) / 2) - 2; CGFloat firstLetterSize = self.font.pointSize * 1.4; for (NSString* word in words) { NSString* letter = [[word substringToIndex:1] uppercaseString]; CGContextSelectFont(context, [self.font.fontName cStringUsingEncoding:NSASCIIStringEncoding], firstLetterSize, kCGEncodingMacRoman); CGContextShowTextAtPoint(context, x, centeredY, [letter cStringUsingEncoding:NSASCIIStringEncoding], [letter length]); x = CGContextGetTextPosition(context).x; NSString* restOfWord = [[[word substringFromIndex:1] uppercaseString] stringByAppendingString:@" "]; CGContextSelectFont(context, [self.font.fontName cStringUsingEncoding:NSASCIIStringEncoding], self.font.pointSize, kCGEncodingMacRoman); CGContextShowTextAtPoint(context, x, centeredY, [restOfWord cStringUsingEncoding:NSASCIIStringEncoding], [restOfWord length]); CGPoint v = CGContextGetTextPosition(context); x = CGContextGetTextPosition(context).x; } } @end 

This implementation does not handle multiple line breaks or adheres to the TextAlignment parameter, it should be simple enough to add later.

Example:

enter image description here

+1
source

try with this

  NSString *string = @"askdfjgjksdfgh"; NSString *upString = [string uppercaseString]; NSLog(@"U %@", upString); 
0
source

It is not possible to change the font size or type of a single letter within a UILabel .

What you want to do is to have 2 labels, one in begging for the first capital letter, and the other for the remaining word.

To access the first letter and the rest of the word you can use:

 NSString * word = @"COMPLETED"; NSString * firstLetter = [word substringToIndex:1]; NSString * remainingWord = [word substringFromIndex:1]; 

What you see in the picture may be images of words, not UILabel s.

0
source

Source: https://habr.com/ru/post/906081/


All Articles