2017-04-24 59 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