As I cannot find any questions/answers for this, I imagine it is not possible.
Is there anyway to set multiple borders on a UIView
.
I am currently setting a standard border with .layer.borderWidth
and layer.borderColor
. I am wondering if I can add a multiple strokes/borders effect to the view.
I need a border of 4.0f in white then another 1.0f in another color.
Three solutions I can think of:
-(void)drawRect
;UIImageView
with a resizable; stretchable image of your borders as background (the best solution performance-wise).Try this,
I'm adding shadow with alpha 1 which will act as the inner border. And the normal border is given as outer border.
You can insert two layers of different widths using this extension:
Use this with different widths/colors to get the desired effect:
Output looks like the following image with outer white border and inner black border:
This is not possible, you will have to fake borders by adding
UIView
's with a background color to your xib/view.That isn't possible with a single
UIView
instance without adding layers.What you can do is create a view that is larger than necessary, set its border appropriately, then add a
CALayer
and position it where you want the inner border and set its border properties appropriately.Using
CALayers
is typically faster than full blownUIView
, but you can also just have a nestedUIView
to achieve the same effect.