我正在努力在线之间增加更多空间。如果有人告诉我们需要做什么,那将会非常有帮助。
使用 NSMutableParagraphStyle 可以解决此问题,但部署目标是ios5.So NSMutableParagraphStyle不受支持。
字体大小:18 线距30
代码:
CustomNote.h
@interface CustomNote : UITextView<UIScrollViewDelegate,
UITextViewDelegate>{ } @end
CustomNote.m
@implementation CustomNote
-(id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
self.delegate = self;
}
return self;
}
-(void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(context, [UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:0.2f].CGColor);
CGContextSetLineWidth(context, 1.0f);
CGContextBeginPath(context);
//NSUInteger numberOfLines = (self.contentSize.height + self.bounds.size.height) / self.font.leading;
NSUInteger numberOfLines = (self.contentSize.height + self.bounds.size.height) / KLineGap;
CGFloat baselineOffset = 6.0f;
for (NSUInteger x = 1; x < numberOfLines; x++) {
//0.5f offset lines up line with pixel boundary
CGContextMoveToPoint(context, self.bounds.origin.x+10, KLineGap *x + 0.5f + baselineOffset);
CGContextAddLineToPoint(context, self.bounds.size.width-10, KLineGap *x + 0.5f + baselineOffset);
}
CGContextClosePath(context);
CGContextStrokePath(context);
}
截图: