小编xex*_*exe的帖子

下划线文本 - 具有不同字体大小的交叉范围中的线条粗细

我正在使用textStorage的属性UITextView.我有字符串和我班级的对象数组TextFormattingElement.此类的一个实例由NSRange(必须在文本中应用此元素)和一些格式化参数组成:

@interface TextFormattingElement : NSObject

@property (nonatomic) NSRange range;
@property (nonatomic, strong) NSString *fontName;   //e.g. @"TimesNewRomanPSMT"
@property (nonatomic) int fontSize;
@property (nonatomic, strong) UIColor *fontColor;
@property (nonatomic) BOOL isBold;
@property (nonatomic) BOOL isItalic;
@property (nonatomic) BOOL isUnderlined;
@property (nonatomic) BOOL isStriked;

@end
Run Code Online (Sandbox Code Playgroud)

现在我遍历这个数组,并连续将这些元素应用到textView的textStorage.我用这个方法:

-(void)setFontWithName:(NSString*)name AndSize:(float)fontSize AndTextColor:(UIColor*)textColor AndIsBold:(BOOL)isBold AndIsItalic:(BOOL)isItalic AndIsUnderlined:(BOOL)isUnderLined andIsStriked:(BOOL)isStriked ToRange:(NSRange)rangeToSet{
   __block UIFont *font = [UIFont fontWithName:name size:fontSize];
   __block UIFontDescriptor *fontDescriptor = [font fontDescriptor];

   [textView.textStorage enumerateAttributesInRange:rangeToSet options:NSAttributedStringEnumerationLongestEffectiveRangeNotRequired usingBlock:^(NSDictionary *attrs, NSRange range, BOOL *stop) { …
Run Code Online (Sandbox Code Playgroud)

uitextview nsattributedstring ios textkit

3
推荐指数
1
解决办法
1745
查看次数

标签 统计

ios ×1

nsattributedstring ×1

textkit ×1

uitextview ×1