2

I currently use an app and I'm trying to replicate an action that occurs in the app.

Here's an example:

enter image description here

As you can see, when my finger is on the selected "UIButton" (at least that's what I think they are), the background image is highlighted. Without releasing my finger, scrolling through the different options highlight that specific UIButton.

I believe each one is a UIButton with no text label, and they've just added a UILabel for each UIButton.

I've done something similar as soon:

enter image description here

However, what I can't figure out is how they managed to make the background highlighted between each selection.

It looks like a combination of a UIControlEvents.TouchDown and UIControlEvents.TouchUpInside.

I've coded up something similar:

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
    }
}

However this approach does not work, because if I perform a .TouchDown, somehow the camera options disappear. If I just add a target for .TouchUpInside, that obviously doesn't work neither because it's only highlighted once I release my finger, and by that time, it would have already taken me to a different view, i.e. Camera or Photo Library.

What's the best approach for how to achieve this?

Thanks.

Pangu
  • 3,391
  • 10
  • 42
  • 103
  • 4
    It is `ActionSheet` style from `UIAlertController` Ref: http://stackoverflow.com/a/32798896/3118477 – sargeras May 17 '16 at 06:47
  • for iPad, don't forget to set action sheet's `popoverPresentationController's` `sourceRect` & `sourceView` otherwise app will crash – Gaurav Sharma May 17 '16 at 10:39

0 Answers0