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)
}
任何想法?
添加按鈕代碼也沒有突出顯示。 –
試試吧,你可以在你的按鈕中設置突出顯示的圖像 –
儘管沒有任何額外的代碼,但我應用程序中的所有其他按鈕都可以高亮顯示。任何想法爲什麼它不在這裏行事? – Prabhu