TransWikia.com

How to make double border lines in the UIImage with the Swift?

Stack Overflow Asked by Antonio Adrian Chavez on February 1, 2021

I have tried to look for the "double border" tricks in Swift to make like this. I have a feeling this could be like a "double border" in UIImage.

enter image description here

Let me know if you know the codes. 🙂

3 Answers

You can just take a UIView and add the UIImageView inside it. Clear the color of the UIView to clear.

This is what I have done using the storyboard.

  1. Added the UIView and a UIImageView inside it, the color of the view is set to clear and the image view is at 15 points from all the sides. Please change as per your requirement (Refer image 1).

  2. This is the view controller code (Refer image 2).

  3. Output(Refer image 3).

Note :Just a basic idea, though you can change the color and the borderwidth etc as per your requirement.

Storyboard layout

View controller code

Output

Answered by AJ16 on February 1, 2021

You need to add borderColor(black) and cornerRadius to the default layer of UIImageView. Along with this, you have to add another sublayer in UIImageView with borderColor as grey.

imageView.layer.borderWidth = 4.0
imageView.layer.borderColor = UIColor.gray.cgColor
imageView.layer.cornerRadius = imageView.frame.width / 2

let borderLayer = CALayer()
borderLayer.frame = imageView.bounds
borderLayer.borderColor = UIColor.black.cgColor
borderLayer.borderWidth = 14.0
borderLayer.cornerRadius = borderLayer.frame.width / 2
imageView.layer.insertSublayer(borderLayer, above: imageView.layer)

See the attached playground demo. See the attached playground sample

Answered by Sumit Jain on February 1, 2021

I think you can add 1 circle (UIView) as a subview between UIImageView and UIImage. For example, you can initialise UIImageView with the gray color for the outer cornerRadius. Then, you add the circle UIView and finally the UIImage.

Or, the alternative can be adding the UIImage before the circle UIView (with transparent background).

I think you can found the similar code here: Image View Double Border

Answered by Peter Du on February 1, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP