9

I have a UIView which includes a UIButton which is partially on UIView. I have a problem when I draw a border on my UIView. Please have a look at my screenshot:

enter image description here

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

4

2 回答 2

6

Thanks for aăâ, I found a solution.

  1. Basically the border is always drawn on top of everything
  2. What I did is:

    • Create a UIView with color of border
    • Create another UIView as the child the main UIView which is a little bit smaller than the first one. The color of this newly create UIView is the main color

Here is the code:

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

The result is:

enter image description here

It's more or less what I need although it's not perfect.

于 2013-03-30T06:08:56.607 回答
0

It could have to do with the order that the objects are drawn. In your storyboard's "Document Outline", views that are lower down in a view controller's outline are drawn later. Perhaps the button is not the last drawn view, like you want?

于 2013-03-30T03:15:18.123 回答