简体   繁体   English

UILabel结合了字体大小

[英]UILabel combine font size

I use a UITextField to input text and automatically the UILabel shows that text. 我使用UITextField输入文本,UILabel自动显示该文本。

Now, I want to increase the second character's font size, ONLY if user typed 3 characters, if user typed less or more than 3, then all characters should get the default font size. 现在,我想增加第二个字符的字体大小,仅当用户键入3个字符时,如果用户输入的数量少于或大于3,则所有字符都应获得默认字体大小。

See attached image. 见附图。

I want to use NSAttributedText, but I don't know how to increase the second character size only. 我想使用NSAttributedText,但我不知道如何仅增加第二个字符大小。 在此输入图像描述

Here's what you do: 这是你做的:

NSMutableAttributedString *text = [[myTextField attributedText] mutableCopy];
NSDictionary *sizeAttributes = @{NSFontAttributeName:[UIFont systemFontOfSize:24.0]};
NSRange secondChar = NSMakeRange(1,1);
[text setAttributes:sizeAttributes range:secondChar];
[myTextField setAttributedText:text];
// might want to release text here, to avoid memory leak

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM