Home Image View Double Border
Reply: 1

Image View Double Border

Logan Published in 2017-12-07 21:03:39Z

I'm calling a function that sets up a UIImageView:

func setupImageView(_ imageView: UIImageView) {}

I want to give that UIImageView an image, round its corners, and give it two different borders.

Here is what I am currently doing:

imageView.image = imageConstants.imageThatIsWanted
imageView.clipsToBounds = true
imageView.layer.cornerRadius = imageView.frame.height / 2
imageView.layer.borderWidth = 3.0
imageView.layer.borderColor = UIColor.white.cgColor

What is the best way to apply a second borderColor of color blue around the white border?

I tried creating a sublayer as a CALayer and giving it a blue border, but this goes behind the image, and also inside of the white border. I also tried drawing a UIBezierPath, but that stays inside of the white border as well.

Rob-4608 Reply to 2017-12-08 05:00:59Z
import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var secondView: UIView!
    @IBOutlet weak var imgView: UIImageView!
    override func viewDidLoad() {
        imgView.layer.cornerRadius = imgView.frame.size.height/2
         secondView.layer.cornerRadius = secondView.frame.size.height/2
        imgView.layer.borderWidth = 5.0
        imgView.layer.borderColor = UIColor.red.cgColor
        imgView.clipsToBounds = true
         secondView.clipsToBounds = true
        // Do any additional setup after loading the view, typically from a nib.

    override func didReceiveMemoryWarning() {
        // Dispose of any resources that can be recreated.


You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.326615 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO