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;
}
參考由@Nick himself.https此ANS://stackoverflow.com/questions/22145978/my-custom-button-is-not-getting-click-in- icarousel-ios – luckyShubhra
你應該檢查你的Button的框架。爲什麼它的dyanamic? – luckyShubhra