이를 둘 다 할 것입니다 내가 한 일이다.
하나.
다음
- (id)initWithFrame:(CGRect)frame imageName:(NSString *)imgName
{
self = [super initWithFrame:frame];
if (self) {
isInScrollview = YES;
CGRect myImageRect = CGRectMake(0, 0, 64, 64);
images = [[UIImageView alloc] initWithFrame:myImageRect];
// here's the change:
// instead of a constant name, use the `imgName` parameter
[images setImage:[UIImage imageNamed:imgName]];
[self addSubview:images];
self.backgroundColor = [UIColor blackColor];
self.layer.borderWidth = 2;
self.layer.borderColor = [UIColor blackColor].CGColor;
self.layer.masksToBounds = YES;
self.layer.cornerRadius = 5;
}
return self;
}
는이 같은 GalleryScrollView
클래스의 - addAttachment:
방법 재 작성 :이 같은 GalleryButton
클래스의 - initWithFrame:
방법을 다시 작성, - [HegakaDragAndDropRecycleBinViewController viewDidLoad]
에, 그리고
- (void) addAttachment:(AttachmentItem *)attachment withImageNamed:(NSString *)imgName
{
// everything stays the same (!), except this line:
GalleryButton *btnAttachment = [[GalleryButton alloc] initWithFrame:CGRectMake(startX, startY, width, height)];
// is to be extended to:
GalleryButton *btnAttachment = [[GalleryButton alloc] initWithFrame:CGRectMake(startX, startY, width, height) imageName:imgName];
...
}
을 이미지의 파일 이름을 지정하면 사용하려면 :
[self.gallery addAttachment:item withImageNamed:@"recyclebin"];
[self.gallery addAttachment:item withImageNamed:@"canadian-maple"];
[self.gallery addAttachment:item withImageNamed:@"light-cherry"];
[self.gallery addAttachment:item withImageNamed:@"mozambique-wenge"];
[self.gallery addAttachment:item withImageNamed:@"canadian-maple"];
결과 :
,
은 왜이 라인에서 에러를 얻을 것이다 : GalleryButton btnAttachment * = [GalleryButton ALLOC] INIT : CGRectMake (STARTX, startY, 폭, 높이) 참고 ImageName : imgName]; in GalleryScrollView.m "instance method -init : imageNamed not found? –
어떻게하면 내 헤더 파일을 선언 할 수 있습니까? –
이제는 작동하지만 HegakaDragAndDropRecycleBinViewController에서 경고가 표시됩니다 viewdidload with attachments withImageNamed not found. with my images [ self.gallery addAttachment : item withImageNamed : @ "recyclebin"]; –