使用Image初始化对象

时间:2012-11-06 14:28:37

标签: ios image initialization init

我有一个名为Company的类,我想重写init方法。我想在此方法中包含公司徽标。我试过这个:

- (id)init
{
self = [super init];
if (self) {
    self.companyName = @"";
    self.companyLogo = nil;
    self.companyDesc = @"";
    self.companyYear = 0;
}
return self;
}

- (id) initWithCompanyName: (NSString*)companyName companyLogo: ***(UIImage*)companyLogo***
 companyDescription: (NSString*)companyDesc foundationYear: (NSInteger)foundationYear
{
self = [self init];
if(self)
{
    self.companyName = companyName;
    self.companyLogo = companyLogo;
    self.companyDesc = companyDesc;
    self.companyYear = foundationYear;
}
return self;
}

显然它不能是UIImage。那么我该如何在初始化中包含图像?

1 个答案:

答案 0 :(得分:2)

使用此调用的类定义可以正常工作:

UIImage *logo = [UIImage imageNamed:@"IMG_0424.JPG"];
Company *company = [[Company alloc]initWithCompanyName:@"iPichy" companyLogo:logo companyDesc:@"iPichy APP Development" foundationYear:2010];