UIView border cover sub-view?

I have a UIView that includes a UIButton that is partially located in a UIView. I have a problem when I draw a border with a UIView. Take a look at my screenshot:

enter image description here

You can see that the border is above UIButton, why? Can anyone suggest? Thanks

+7
source share
2 answers

Thanks for aฤƒรข , I found a solution.

  • Basically a border is always drawn on top of everything
  • What I've done:

    • Create a UIView with a border color
    • Create another UIView as a child of the UIView, which is slightly smaller than the first. The color of this newly created UIView is the primary color.

Here is the code:

self.layer.cornerRadius = 15; self.layer.masksToBounds = YES; self.backView.layer.cornerRadius = 15; self.backView.layer.masksToBounds = YES; 

Result:

enter image description here

This is more or less what I need, although it is not perfect.

+4
source

This may be due to the order in which objects are drawn. In your storyboard "Document Structure", views that are lower in the outline of the view controller are displayed later. Perhaps the button is not the last drawn view, how do you want?

0
source

All Articles