I have created a method already that returns a UIImage as follows:
- (UIImage *)circularOverlayMask
{
// Constants
CGRect rect = self.navigationController.view.bounds;
CGFloat width = rect.size.width;
CGFloat height = rect.size.height;
CGFloat diameter = width-(kInnerEdgeInset*2);
CGFloat radius = diameter/2;
CGPoint center = CGPointMake(width/2, height/2);
UIColor *fillColor = [UIColor colorWithWhite:0 alpha:0.5];
// Create the image context
UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0);
// Create the bezier paths
UIBezierPath *clipPath = [UIBezierPath bezierPathWithRect:rect];
UIBezierPath *maskPath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(center.x-radius, center.y-radius, diameter, diameter)];
[clipPath appendPath:maskPath];
clipPath.usesEvenOddFillRule = YES;
[clipPath addClip];
[fillColor setFill];
[clipPath fill];
UIImage *_maskedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return _maskedImage;
}
This works as expected and is currently in my View Controller code. I am trying to better refactor the code for the view controller and would like to move this to an appropriate subclass.
My initial thoughts were to subclass UIImage
and return the image somehow. Another thought was to subclass UIImageView
and within the init
method call initWithImage
then [self circularOverlayMask];
. Another thought would be to simply subclass NSObject
and add the method, then import where needed and call a public +
method.
Question
What is the correct approach to refactoring this simple method into a relevant subclass?