iOS
iOS

Reputation: 213

How to use a image created by UIImage category

I have created a method to create a circle which is working fine when i am using this method in the same class but when i making a category of this doesnot show up

#import "UIImage+circle.h"
@implementation UIImage (circle)    
- (UIImage * ) makeImageofColor:(UIColor *)color
 {
        UIBezierPath *circle = [UIBezierPath
                                bezierPathWithOvalInRect:CGRectMake(0, 0, 15, 15)];
        UIGraphicsBeginImageContext(CGSizeMake(15, 15));
        CGContextRef context = UIGraphicsGetCurrentContext();
        CGContextSetFillColorWithColor(context, [UIColor greenColor].CGColor);
        [circle fill];
        UIImage *bezierImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return bezierImage;
    }
   @end

and in ViewController.m

- (void)viewDidLoad
 {
      [super viewDidLoad];
      UIImage *img;
      self.ImageView1.image=[img makeImageofColor:[UIColor greenColor]];
}

Upvotes: 0

Views: 1178

Answers (2)

Surya Subenthiran
Surya Subenthiran

Reputation: 2217

In the "UIImage+circle.h" file declare your category method like this

- (UIImage * ) makeImageofColor:(UIColor *)color;

and import "UIImage+circle.h" in "ViewController.m"

This will solve your problem.

Upvotes: 0

cjd
cjd

Reputation: 549

This is reference problem,Simply replace instance method declaration

- (UIImage * ) makeImageofColor:(UIColor *)color 

with class method declaration

+ (UIImage * ) makeImageofColor:(UIColor *)color

and call

self.ImageView1.image=[UIImage makeImageofColor:[UIColor greenColor]];

Upvotes: 2

Related Questions