【问题标题】:How to Add a button into iCarousel View?如何在 iCarousel 视图中添加按钮?
【发布时间】:2017-07-27 04:45:10
【问题描述】:

我正在使用 iCarousel 来显示图像。但我想在 iCarousel 中添加一个按钮。我实现了它,但问题是自定义按钮操作不起作用,当我单击按钮时只有 didSelectItem 起作用。这是我的代码。请哪位大神帮帮我。

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

【问题讨论】:

标签: ios objective-c iphone xcode8


【解决方案1】:

您是否启用了 UserInteraction?

启用用户交互

[view setUserInteractionEnabled:YES];

【讨论】:

  • 一切正常。谢谢
猜你喜欢
  • 2017-08-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-11
  • 2011-08-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多