
这是我尝试过的:
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];解决方法 例如,要获得:
说这个:
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中第一个字母的字体大小全部内容,希望文章能够帮你解决ios – 增加UILabel.text中第一个字母的字体大小所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)