2017-07-27 68 views
0

我使用iCarousel用于显示图像。但我想在iCarousel中添加一个按钮。我实现了它,但问题是自定义按钮操作不起作用,当我单击按钮时,只有didSelectItem工作。这是我的代码。请,任何人帮助我。如何将按钮添加到iCarousel视图?

- (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; 
} 
+0

参考由@Nick himself.https此ANS://stackoverflow.com/questions/22145978/my-custom-button-is-not-getting-click-in- icarousel-ios – luckyShubhra

+0

你应该检查你的Button的框架。为什么它的dyanamic? – luckyShubhra

回答

0

您是否启用UserInteraction?

启用用户交互

[view setUserInteractionEnabled:YES]; 
+0

工作正常。谢谢 – Abir