我目前使用的應用程序,我試圖複製應用程序中發生的操作。如何從這個應用程序複製UIButton選擇的設計和動作?
下面是一個例子:
正如你所看到的,當我的手指在選擇了「UIButton
」(至少這是我認爲他們是),背景圖像被突出顯示。不釋放我的手指,滾動瀏覽不同的選項會突出顯示特定的UIButton
。
我相信每個人都是UIButton
沒有文字標籤,他們剛剛爲每個UIButton
添加了UILabel
。
我儘快做類似的事情:
不過,我想不通他們是如何設法讓每個選擇的背景高亮顯示。
它看起來像是UIControlEvents.TouchDown
和UIControlEvents.TouchUpInside
的組合。
我已經編寫了類似的東西:
cameraButton.addTarget(self, action: #selector(AddClothesViewController.selectCameraOptions(_:)), forControlEvents: .TouchUpInside)
cameraButton.addTarget(self, action: #selector(AddClothesViewController.selectCameraOptionsHighlighted(_:)), forControlEvents: .TouchDown)
func selectCameraOptionsHighlighted(button: UIButton)
{
if button == cameraButton
{
print("GO HERE")
cameraButton.setImage(UIImage(named: "highlighted background"), forState: .Normal)
}
}
func selectCameraOptions(button: UIButton)
{
if button == cameraButton
{
// DO STUFF
}
}
但是這種方法是行不通的,因爲如果我執行.TouchDown
,不知何故相機選項中消失。如果我只是添加目標.TouchUpInside
,那顯然不起作用,因爲只有當我釋放手指時纔會突出顯示,到那時,它已經讓我看到不同的視角,即相機或照片庫。
如何實現這一目標的最佳方法是什麼?
謝謝。
這是來自'UIAlertController'的'ActionSheet'風格Ref:http://stackoverflow.com/a/32798896/3118477 – sargeras
對iPad使用UIActionSheet – 2016-05-17 06:49:32
,不要忘記設置操作表的'popoverPresentationController's'sourceRect'& 'sourceView'否則app會崩潰 –