Change UIPopoverView background + arrow color

此生再无相见时 提交于 2019-12-01 13:43:56

问题


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 "UIPopoverControllers". Does this apply here too, meaning the answer is "no"?)

Isn't this something I should be able to address in the prepareForSegue method triggering the popover? How can I reach the according view to change its appearance?


回答1:


I found the solution. Subclassing is not necessary anymore with iOS8! The background can be accessed and changed like this from within the tableview -> navigation -> popoverPresentationController

    self.navigationController?.popoverPresentationController?.backgroundColor = UIColor.redColor()

More information about this in WWDC session 214.




回答2:


You can simply modify popover like this:

    let popoverViewController = self.storyboard?.instantiateViewControllerWithIdentifier("popoverSegue")
    popoverViewController!.popoverPresentationController?.delegate = self
    popoverViewController!.modalPresentationStyle = .Popover


    let popoverSize = CGSize(width: 150, height: 60)
    popoverViewController!.preferredContentSize = popoverSize
    let popover = popoverViewController!.popoverPresentationController
    popover?.delegate = self
    popover?.permittedArrowDirections = .Up
    popover?.sourceView = self.view

    //change background color with arrow too!
    popover?.backgroundColor = UIColor.whiteColor()
    popover?.sourceRect = CGRect(x: self.view.frame.width, y: -10, width: 0, height: 0)
    presentViewController(popoverViewController!, animated: true, completion: nil)


来源:https://stackoverflow.com/questions/25403258/change-uipopoverview-background-arrow-color

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!