2017-04-24 62 views
1

我在集合视图内有一个按钮,但与应用程序周围的其他按钮不同,此按钮在您点击时不会突出显示。我尝试了一些建议的操作,比如打开按钮上的突出显示触摸,以及将delaysContentTouches设置为false。集合视图中的按钮不会突出显示在水龙头上

func createCollectionView() { 
     let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout() 
     layout.sectionInset = UIEdgeInsets(top: 15, left: 10, bottom: 10, right: 10) 
     layout.itemSize = CGSize(width: view.frame.width, height: 50) 

     cv = UICollectionView(frame: view.frame, collectionViewLayout: layout) 
     cv.frame = CGRectMake(0, 50, view.frame.width, 250); 
     cv.dataSource = self 
     cv.delegate = self 
     cv.registerNib(UINib(nibName: "cvCell", bundle: nil), forCellWithReuseIdentifier: "cell") 
     cv.backgroundColor = UIColor.whiteColor() 

     //suggested on other SO answers: 
     cv.delaysContentTouches = false 

     for view in cv.subviews { 
      if view is UIScrollView { 
       (view as? UIScrollView)!.delaysContentTouches = false 
       break 
      } 
     } 
    } 


//Button: 
var onTap: ((cvCell) -> Void)? 
    @IBAction func btn(sender: AnyObject) { 
     onTap?(self) 
    } 

//CollectionView select: 
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { 
    let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! cvCell 
    cell.btn.setTitle("follow", forState: .Normal) 
} 

任何想法?

+0

添加按钮代码也没有突出显示。 –

+0

试试吧,你可以在你的按钮中设置突出显示的图像 –

+0

尽管没有任何额外的代码,但我应用程序中的所有其他按钮都可以高亮显示。任何想法为什么它不在这里行事? – Prabhu

回答

2

如果您的按钮类型是cell.btn.buttonType == UIButtonType.system,那么它会自动显示按钮标题显示上的突出显示效果。否则cell.btn.buttonType == UIButtonType.custom比你需要给你自己突出显示的效果。

enter image description here