[英]Buttons created programmatically doesn't receive touch up inside events… UICollectionViewCell
I'm creating Collection View Cells programmatically using Facade framework to position it right. 我正在使用Facade框架以编程方式创建Collection View Cells,以使其正确定位。 Unfortunately buttons inside cells doesn't react to touches.
不幸的是,单元格内的按钮对触摸没有反应。 Collection View is created using storyboard.
集合视图是使用情节提要创建的。 CollectionViewCell appearance loading:
CollectionViewCell外观加载:
_likesButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_likesButton setBackgroundColor:[UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:0.10]];
_likesButton.contentEdgeInsets = UIEdgeInsetsMake(5, 8, 5, 8);
_likesButton.contentVerticalAlignment = UIControlContentVerticalAlignmentFill;
_likesButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentFill;
[_likesButton setAttributedTitle:[self attributedSpacedStringFromString:@"+10039" withColor:[UIColor flatWhiteColor] withFont:[UIFont fontWithName:@"OpenSans-Bold" size:12]] forState:UIControlStateNormal];
_likesButton.layer.cornerRadius = 12;
[_likesButton sizeToFit];
_likesButton.userInteractionEnabled = YES;
In Collection View: 在集合视图中:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
cell.likesButton.tag = indexPath.row;
[[cell likesButton] addTarget:self action:@selector(showAlert:) forControlEvents:UIControlEventTouchUpInside];
return cell;
}
What I'm doing wrong? 我做错了什么? Best regards,
最好的祝福,
Adrian. 阿德里安
Ok I just figured it out... I had image as background (UIButton was subview) and UIImageView has userInteractionEnabled disabled as default. 好的,我刚刚弄清楚了...我将图像作为背景(UIButton是子视图),UIImageView将userInteractionEnabled禁用为默认值。 Setting this property to YES, fixed issue.
将此属性设置为“是”,已解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.