我有UIScrollView
动态添加UIImageViews
。
在故事板上
运行程序后
添加图片的代码在我的自定义类上。该课程未分配到任何视图:
- (id)initWithModel:(UIScrollView *)scroller page:(NSInteger)page image:(UIImage*)image{
self = [super init];
if (self) {
_scrollView = scroller;
_imageScrollIndex = page;
_image = image;
_frame = _scrollView.bounds;
_frame.origin.x = _frame.size.width * _imageScrollIndex;
_frame.origin.y = 0.0f;
_frame = CGRectInset(_frame, 10.0f, 0.0f);
_imageView = [[UIImageView alloc] initWithImage:_image];
_imageView.contentMode = UIViewContentModeScaleAspectFit;
_imageView.frame = _frame;
//adding delete image button
CGRect frame = _imageView.frame;
frame.origin.x = frame.size.width/2;
frame.origin.y = -frame.size.height/2+45;
//_imageView.userInteractionEnabled = YES;
UIButton *deleteImgButton = [[UIButton alloc] initWithFrame:frame];
deleteImgButton.userInteractionEnabled = YES;
[deleteImgButton addTarget:self action:@selector(clickedDeleteButton:)forControlEvents:UIControlEventTouchUpInside];
[deleteImgButton setImage:[UIImage imageNamed:@"close.png"] forState:UIControlStateNormal];
[_imageView addSubview:deleteImgButton];
////
[_scrollView addSubview:_imageView];
}
return self;
}
- (void)clickedDeleteButton:(UIButton*)button
{
printf("hi:\n");
}
我想成为:
userinteractionenabled
的{{1}}是任何想法如何?
答案 0 :(得分:0)
_scrl_ipad.contentSize = CGSizeMake(768,273 * temp);
_scrl_ipad.showsVerticalScrollIndicator=NO;
UIButton *btn_scrl=[UIButton buttonWithType:UIButtonTypeCustom];
[btn_scrl setFrame:CGRectMake(0,0, 328, 243)];
btn_scrl.tag=i-1;
[btn_scrl addTarget:self action:@selector(btn_scrl_tag:) forControlEvents:UIControlEventTouchUpInside];
[_scrl_ipad addSubview:btn_scrl];
-(IBAction)btn_scrl_tag:(id)sender
{
UIButton *btn = (UIButton *)sender;
NSLog(@"%d",btn.tag);
}