Ios 以编程方式创建的按钮不会收到内部事件的润色。。。UICollectionViewCell
我正在使用Facade框架以编程方式创建集合视图单元,以正确定位它。不幸的是,细胞内的按钮对触摸没有反应。 集合视图是使用故事板创建的。 CollectionViewCell外观加载:Ios 以编程方式创建的按钮不会收到内部事件的润色。。。UICollectionViewCell,ios,uicollectionview,uicollectionviewcell,uicontrolevents,Ios,Uicollectionview,Uicollectionviewcell,Uicontrolevents,我正在使用Facade框架以编程方式创建集合视图单元,以正确定位它。不幸的是,细胞内的按钮对触摸没有反应。 集合视图是使用故事板创建的。 CollectionViewCell外观加载: _likesButton = [UIButton buttonWithType:UIButtonTypeCustom]; [_likesButton setBackgroundColor:[UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:0.10]]; _lik
_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;
在集合视图中:
- (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;
}
我做错了什么?
致以最良好的祝愿
阿德里安。好吧,我刚想出来。。。
我将图像作为背景UIButton是子视图,UIImageView默认禁用userInteractionEnabled。将此属性设置为“是”,已修复问题。是否确实在单元格中添加了按钮?尝试为按钮提供背景色,然后查看。。。