我试图使用FontAwesome在单个字符串中显示一些文本和图标.
这是我有的:
NSString *icon = [NSString fontAwesomeIconStringForIconIdentifier:@"icon-map-marker"]; NSString *locationString = [NSString stringWithFormat:@"%@ %@", icon, otherNormalString];
基本上我想让地图标记出现在显示的位置前面.使用FontAwesome应该让这很简单,但我不能让它正常工作.
如果我NSLog字符串图标,这也是显示的内容:
有关如何正确完成此任务的任何想法?
字符串不带任何样式信息(包括字体).为了包含字体信息,您需要制作一个NSAttributedString
.所有这个-fontAwesomeIconStringForIconIdentifier
方法都是在给定标识符的情况下返回unicode值.
假设您正在使用ios-fontawesome,您需要执行以下操作:
... your locationString assignment ... NSMutableAttributedString *astring = [[NSMutableAttributedString alloc] initWithString:locationString]; [astring addAttribute:NSFontAttributeName value:[UIFont iconicFontOfSize:size] range:NSMakeRange(0,1)]; // The first character
然后,您可以将属性字符串分配给标签的attributedText
属性,或者类似地显示它.