我正在努力增加行之间的空间。如果有人告诉需要做什么,那将非常有帮助。
使用NSMutableParagraphStyle可以解决此问题,但部署目标是 ios5。因此不支持 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);
}
截屏: