开发当中总会遇到字体小看不清楚的情况,我这里做了一个放大镜的功能。直接上代码:
- (void)setPointToMagnify:(CGPoint)pointToMagnify
{
_pointToMagnify = pointToMagnify;
CGPoint center = CGPointMake(pointToMagnify.x, self.center.y);
if (pointToMagnify.y > CGRectGetHeight(self.bounds) * 0.5) {
center.y = pointToMagnify.y - CGRectGetHeight(self.bounds) / 2;
}
self.center = center;
[self.contentLayer setNeedsDisplay];
}
- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx
{
CGContextTranslateCTM(ctx, self.frame.size.width * 0.5, self.frame.size.height * 0.5);
CGContextScaleCTM(ctx, 1.2, 1.2);
CGContextTranslateCTM(ctx, -1 * self.pointToMagnify.x, -1 * self.pointToMagnify.y);
[self.viewToMagnify.layer renderInContext:ctx];
}