Ios 如何使用UIImage类别创建的图像
我已经创建了一个方法来创建一个圆,当我在同一个类中使用这个方法时,这个圆工作得很好,但是当我创建一个这样的类别时却没有显示出来Ios 如何使用UIImage类别创建的图像,ios,iphone,objective-c,uiimage,uibezierpath,Ios,Iphone,Objective C,Uiimage,Uibezierpath,我已经创建了一个方法来创建一个圆,当我在同一个类中使用这个方法时,这个圆工作得很好,但是当我创建一个这样的类别时却没有显示出来 #import "UIImage+circle.h" @implementation UIImage (circle) - (UIImage * ) makeImageofColor:(UIColor *)color { UIBezierPath *circle = [UIBezierPath
#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
在ViewController.m中
- (void)viewDidLoad
{
[super viewDidLoad];
UIImage *img;
self.ImageView1.image=[img makeImageofColor:[UIColor greenColor]];
}
这是引用问题,只需替换实例方法声明即可
- (UIImage * ) makeImageofColor:(UIColor *)color
+ (UIImage * ) makeImageofColor:(UIColor *)color
使用类方法声明
- (UIImage * ) makeImageofColor:(UIColor *)color
+ (UIImage * ) makeImageofColor:(UIColor *)color
打电话
self.ImageView1.image=[UIImage makeImageofColor:[UIColor greenColor]];
在“UIImage+circle.h”文件中,像这样声明您的分类方法
- (UIImage * ) makeImageofColor:(UIColor *)color;
并在“ViewController.m中导入“UIImage+circle.h”
这将解决您的问题。您是否在.h文件中声明了category方法?