Я пытаюсь написать пользовательский UITextView с возможностью выделения частей текста в качестве результатов поиска. Для этого я помещаю свой собственный CATextLayer вместо обычного текстового слоя и хочу использовать NSMutableAttributedString для рисования текста на CATextLayer с выделенными частями текста.CATextLayer игнорирует атрибуты CTParagraphStyleSetting
Проблема в том, что я не могу установить Linespacing для текста. Я могу установить атрибуты одинакового шрифта и fontcolor NSMutableAttributedString через [attrString setAttributes: attributes range: range]; , но все атрибуты в CTParagraphStyleSetting игнорируются.
- (void)redrawSelectableTextLayer
{
attrString = [[NSMutableAttributedString alloc] initWithString:self.text];
//Write the attributes of the attributed String
NSRange range = NSMakeRange(0, attrString.length);
NSMutableDictionary* attributes = [NSMutableDictionary dictionaryWithCapacity:3];
[attributes setObject:(id)[UIColor redColor].CGColor forKey:(NSString*)kCTForegroundColorAttributeName];
CTFontRef aFont = CTFontCreateWithName((CFStringRef)self.font.fontName, self.font.pointSize, NULL);
if(aFont){
[attributes setObject:(id)aFont forKey:(NSString*)kCTFontAttributeName];
}
CTParagraphStyleSetting settings[1];
CGFloat linespace = 140.0;
CTLineBreakMode lbm = kCTLineBreakByCharWrapping;
settings[0].spec = kCTParagraphStyleSpecifierLineBreakMode;
settings[0].valueSize = sizeof(CTLineBreakMode);
settings[0].value = &lbm;
CTParagraphStyleRef style = CTParagraphStyleCreate(settings, 1);
[attributes setObject:(id)style forKey:(NSString*)kCTParagraphStyleAttributeName];
CFRelease(style);
[attrString setAttributes:attributes range:range];
//Set current Size of view
CGFloat width = originalTextLayer.frame.size.width - 18.0;
CGFloat height = [attrString boundingHeightForWidth:width];
selectedTextLayer.frame = CGRectMake(9.0f, 11.0f, width, height);
//Draw the attributed String to the CATextLayer
selectedTextLayer.string = attrString;
}
Задает ли CATextLayer эти параметры по умолчанию или есть что-то, что я делаю неправильно?