2016-09-29 23 views
0

我有以下代碼:的UIButton不會改變文字顏色,當有長按手勢識別

deleteAllButton.setTitle("Delete", forState: .Normal) 
     deleteAllButton.titleLabel?.numberOfLines = 2 
     deleteAllButton.setTitleColor(UIColor.blackColor(), forState: .Normal) 
     deleteAllButton.titleLabel?.font = UIFont.systemFontOfSize(keyboardFontSize) 
    // deleteAllButton.addTarget(self, action: #selector(deletekeyPressed), forControlEvents: .TouchUpInside) 

     let deleteLPGR = UILongPressGestureRecognizer(target: self, action: #selector(deleteButtonLongPress)) 
     deleteLPGR.minimumPressDuration = 0 
     deleteLPGR.delaysTouchesBegan = true 

     deleteAllButton.addGestureRecognizer(deleteLPGR) 

通常,當一個UIButton按下文本會自動改變顏色以表明它處於「按下」州。但是,由於我添加了長按手勢識別器,該按鈕並不表示它處於「按下」狀態。

如何仍然允許觸摸事件通過按鈕,以便用戶感覺按鈕實際上「按下」?

回答

0

我認爲你不需要添加手勢識別器。

只是嘗試設置titlecolor爲國家白標明的,它應該工作

deleteAllButton.setTitleColor(UIColor.redColor(), forState: .Highlighted) 

希望這將解決您的問題。

0

只要改變deleteLPGR.minimumPressDuration = 0deleteLPGR.minimumPressDuration = 1那麼當你按下

你可以看到顏色變化