Abir Abir - 2 years ago 104
iOS Question

How to Add a button into iCarousal View?

I am use iCarousal for showing an image. But i want to add a button into iCarousal. i implemented it but problem is that, custom button action does not work, only didselectitem work when i click into button. here is my code. please any one help me out.

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view


NSString *str=[[appController
sharedappController].allLibraryImagesArrM objectAtIndex:index];
view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200.0f, 200.0f)];
((UIImageView *)view).image = [[appController sharedappController].allLibraryImagesArrM objectAtIndex:index];

view.contentMode = UIViewContentModeScaleAspectFit;
//[view addSubview:cross];

UIButton *cross = [[UIButton alloc]init];
cross.frame = CGRectMake(view.frame.size.width/2+30, view.frame.origin.y+30, 40, 40);
[cross setBackgroundImage:[UIImage imageNamed:@"circle"] forState:UIControlStateNormal];
[cross addTarget:self action:@selector(crossMethod) forControlEvents:UIControlEventTouchUpInside];
UIImage *buttonImage = [UIImage imageNamed:@"cross.png"];
[cross setBackgroundImage:buttonImage forState:UIControlStateNormal];
[view addSubview:cross];
return view;


Answer Source

add this:

[view setUserInteractionEnabled:YES];

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download