Change UIPopoverView background + arrow color

后端 未结 5 1442
猫巷女王i
猫巷女王i 2021-01-03 18:19

Is there a way to simply change the UIPopoverView background color (including its arrow) on iOS8?

(I did read a couple of articles on customizing \"UIPopove

5条回答
  •  渐次进展
    2021-01-03 19:11

    Seems like that popoverPresentationController.backgroundColor no longer works in iOS13.

    Popover arrows now appear to take on the color of the popover viewController's view.backgroundColor.

    Here's the whole code for the demo below:

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if let sourceButton = sender as? UIButton, let popover = segue.destination.popoverPresentationController {
            popover.sourceView = sourceButton.superview
            popover.sourceRect = sourceButton.frame
            popover.permittedArrowDirections = [.left]
            popover.delegate = self
            segue.destination.preferredContentSize = CGSize(width: 100, height: 100)
            //popover.backgroundColor = sourceButton.tintColor  //old way
            segue.destination.view.backgroundColor = sourceButton.tintColor  //new way
        }
    }
    
    @IBAction func btnTap(_ sender: Any) {
        performSegue(withIdentifier: "popoverSegue", sender: sender)
    }
    
    func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
        return .none
    }
    

提交回复
热议问题