0

我使用EGOTextView进行富文本编辑。但是 的lineHeight看起来EGOTextView比 中的要小一些UITextView,它们都设置了相同的字体。我尝试在默认属性中设置kCTParagraphStyleSpecifierMinimumLineHeightand kCTParagraphStyleSpecifierMaximumLineHeight,但这不是一个好的解决方案,因为我需要插入必须修改lineHeight. 任何帮助将不胜感激:)

在此处输入图像描述在此处输入图像描述

EGOTextView.m

- (void)viewDidLoad {
[super viewDidLoad];
UISegmentedControl *segment = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"UITextView", @"EGOTextView", nil]];
segment.segmentedControlStyle = UISegmentedControlStyleBar;
[segment addTarget:self action:@selector(segmentChanged:) forControlEvents:UIControlEventValueChanged];
self.navigationItem.titleView = segment;
[segment release];

if (_textView==nil) {
    UITextView *textView = [[UITextView alloc] initWithFrame:self.view.bounds];
    textView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    textView.font = [UIFont systemFontOfSize:14];
    [self.view addSubview:textView];
    self.textView = textView;
    [textView release];
}

if (_egoTextView==nil) {
    EGOTextView *view = [[EGOTextView alloc] initWithFrame:self.view.bounds];
    view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    view.delegate = (id<EGOTextViewDelegate>)self;
    [self.view addSubview:view];
    self.egoTextView = view;
    self.egoTextView.delegate = self;
    [view release];  
    [self.egoTextView setFont:[UIFont systemFontOfSize:14]];
}
[segment setSelectedSegmentIndex:1];
}
4

1 回答 1

1

您可以将 设置kCTParagraphStyleSpecifierLineSpacing为您想要分隔线的点数CTParagraphStyleSettingNSAttributedString或者,您也可以使用kCTParagraphStyleSpecifierLineHeightMultiple, 指定行高倍数,以将行高增加一个因子。

这是一个简单的例子:

CGFloat lineSpacing = 0.f; // spacing, in points
CGFloat lineHeightMultiple = 0.f; // line height multiple

CTParagraphStyleSetting paragraphStyles[2] = {
    {.spec = kCTParagraphStyleSpecifierLineSpacing, .valueSize = sizeof(CGFloat), .value = (const void *)&lineSpacing},
    {.spec = kCTParagraphStyleSpecifierLineHeightMultiple, .valueSize = sizeof(CGFloat), .value = (const void *)&lineHeightMultiple}
};

CTParagraphStyleRef paragraphStyle = CTParagraphStyleCreate(paragraphStyles, 10);
[NSDictionary dictionaryWithObject:(__bridge id)paragraphStyle
                            forKey:(NSString *)kCTParagraphStyleAttributeName];
CFRelease(paragraphStyle);
于 2012-11-14T22:04:30.070 回答