UIView default styling has rounded corners?

一个人想着一个人 提交于 2019-12-01 07:26:15

问题


I am using a UIPopoverController to display a UIView. The layout is somewhat similar to a UISplitViewController so it is very strange looking to have rounded corners on the "detail view" because it leaves a small gap. I have not been able to find anything at all relating to other people having this problem, but these rounded corners seem to be the default style. Is it possible to remove them?

Things that might help:

  • I load my view from a nib file, but I have currently made no changes to the default UIView
  • I tried setting clipsToBound = NO in viewDidLoad
  • I tried setting layer.cornerRadius = 0 in viewDidLoad

There also seems to be a shadow on the top part of the view, but it is hard to tell. Is there any way I can just get rid of all this default styling? I just want a blank square.


回答1:


There is no supported way to make the view inside of your UIPopoverController not have rounded corners. The internal code of the UIPopoverController adds your view to a view with rounded corners that clips to bounds.

There may be a hackish way to do it, i.e. waiting until the UIPopoverController is shown and then traversing through all of the parent's of your view and setting them all to have cornerRadius = 0; and clipsToBounds = NO;, but even if you find a solution it might not be compatible with all versions of iOS and if Apple changes some internal code of UIPopoverController in the future then your solution could break.

If you really want to do this then the best way to go is to create your own class that mimics the UIPopoverController functionality.




回答2:


The black gradient color frame with rounded corner is default for UIPopoverController. However you can use a custom class to set the background view . Here try following link.

change color navigation controller in a popover




回答3:


For anyone who uses UIPopoverPresentationController, the following should work.

override open func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    view.superview?.layer.cornerRadius = 0
}


来源:https://stackoverflow.com/questions/11401530/uiview-default-styling-has-rounded-corners

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