Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom Action controller, Swift

Does anyone know how I can code up this custom alert controller (The top area especially) - currently found on the Apple music App. Maybe there is a known library that can do it.

I am aware this is how you an action controller is coded?

let alertController = UIAlertController(title: nil, message: "Top Message Here", preferredStyle: .ActionSheet)


        let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel) { (action) in
            // Drop View Pop up

        }

        alertController.addAction(cancelAction)

        let action1 = UIAlertAction(title: "Action Title", style: .Default) { (action) in

            //Code to Execute

        }

        alertController.addAction(action1)
        self.presentViewController(alertController, animated: true) {
            // ...

        }

enter image description here

like image 367
Gugulethu Avatar asked Feb 19 '16 11:02

Gugulethu


People also ask

What is custom actions on Iphone?

Custom Actions simplify the experience for people using assistive technologies with your app and they can help you reduce the number of swipes and taps that are required to navigate through your interface and perform interactions.


1 Answers

Here is an example:

@IBAction func show() {
    let actionSheet = UIAlertController(title: "\n\n\n\n\n\n", message: nil, preferredStyle: .ActionSheet)

    let view = UIView(frame: CGRect(x: 8.0, y: 8.0, width: actionSheet.view.bounds.size.width - 8.0 * 4.5, height: 120.0))
    view.backgroundColor = UIColor.greenColor()
    actionSheet.view.addSubview(view)

    actionSheet.addAction(UIAlertAction(title: "Add to a Playlist", style: .Default, handler: nil))
    actionSheet.addAction(UIAlertAction(title: "Create Playlist", style: .Default, handler: nil))
    actionSheet.addAction(UIAlertAction(title: "Remove from this Playlist", style: .Default, handler: nil))

    actionSheet.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: nil))
    presentViewController(actionSheet, animated: true, completion: nil)
}
like image 142
Ahmed Onawale Avatar answered Oct 12 '22 07:10

Ahmed Onawale