gpt4 book ai didi

ios - 增加 UILabel.text 中第一个字母的字体大小

转载 作者:可可西里 更新时间:2023-11-01 17:08:55 25 4
gpt4 key购买 nike

我希望 UILabel 的第一个字母与其他字母的字体大小不同,字体大小大一些。需要一些关于如何做的指导。标签有很多字。

这是我试过的:

NSArray * words = [Label.text componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSString *firstLetter = [[words objectAtIndex:0] substringToIndex:1];

但是在增加 NSString 的大小时遇到​​了困难。有没有更好的办法?欢迎给我建议和指导..谢谢..

编辑:

[Label setFont:[UIFont fontWithName:@"Arial" size:12.f]];
NSArray * words = [Label.text componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
UIFont *fontFirst=[UIFont fontWithName:@"Arial" size:15.f];
NSDictionary *attrsDictFirst=[NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
NSAttributedString *finalString=[[NSAttributedString alloc] initWithString:[[words objectAtIndex:0] substringToIndex:1] attributes:attrsDictFirst];

最佳答案

例如,要得到这个:

enter image description here

这样说:

NSString* s2 = @"Fourscore and seven years ago, our fathers brought forth "
@"upon this continent a new nation, conceived in liberty and dedicated "
@"to the proposition that all men are created equal.";
NSMutableAttributedString* content2 =
[[NSMutableAttributedString alloc]
initWithString:s2
attributes:
@{
NSFontAttributeName:
[UIFont fontWithName:@"HoeflerText-Black" size:16]
}];
[content2 setAttributes:
@{
NSFontAttributeName:[UIFont fontWithName:@"HoeflerText-Black" size:24]
} range:NSMakeRange(0,1)];
[content2 addAttributes:
@{
NSKernAttributeName:@-4
} range:NSMakeRange(0,1)];

NSMutableParagraphStyle* para2 = [NSMutableParagraphStyle new];
para2.headIndent = 10;
para2.firstLineHeadIndent = 10;
para2.tailIndent = -10;
para2.lineBreakMode = NSLineBreakByWordWrapping;
para2.alignment = NSTextAlignmentJustified;
para2.lineHeightMultiple = 1.2;
para2.hyphenationFactor = 1.0;
[content2 addAttribute:NSParagraphStyleAttributeName
value:para2 range:NSMakeRange(0,1)];

然后将 content2 分配给标签的 attributedText

关于ios - 增加 UILabel.text 中第一个字母的字体大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15976595/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com