//normal ruler
for(inti =0; i <=_intervalNum; i++) {
if(i %_intervalNum) {//normal tick
CGContextSetStrokeColorWithColor(context, _tickColor.CGColor);
CGContextMoveToPoint(context,self.tickSpace*i, y + (_bigTickLen-_tickLen)/2);
CGContextAddLineToPoint(context,self.tickSpace*i, y + (_bigTickLen-_tickLen)/2+_tickLen);
}
else{//big tick
CGContextSetStrokeColorWithColor(context, _bigTickColor.CGColor);
CGContextMoveToPoint(context,self.tickSpace*i, y);
CGContextAddLineToPoint(context,self.tickSpace*i, y +_bigTickLen);
//draw big tick value
NSString*num = [NSStringstringWithFormat:@"%.f", i*_minUnit+_fromNum];
NSDictionary *attribute = @{NSFontAttributeName:_numFont, NSForegroundColorAttributeName:_numColor};
CGFloat width = [num boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX) options:0 attributes:attribute context:nil].size.width;
[numdrawInRect:CGRectMake(self.tickSpace*i - width/2,_bigTickLen+10, width,14)withAttributes:attribute];
}
CGContextStrokePath(context);
}
网友评论