Attempt to set UIImage border

I am new to fast and I am trying to set a black border around my UIImageView , but I cannot do this. This is my code.

 @IBOutlet weak var flagImage: UIImageView! var image = UIImage(named: "estonia") override func viewDidLoad() { super.viewDidLoad() flagImage.layer.borderColor = UIColor(red: 0.5, green: 0.5, blue: 0.5, alpha: 1.0).CGColor flagImage.layer.cornerRadius = 5.0 flagImage.contentMode = .scaleAspectFit flagImage.image = image } 

Can I get help on this?

+9
ios swift uiimage uiimageview
source share
4 answers

You set the frame color for the imageView, but as you might expect to see the color without any area to fill. So,

 flagImage.layer.borderWidth = 2 /** as you wish **/ 

Gives the area around the imageView 2 thick to fill in the color you gave.

+19
source share

Try to add this.

Objective-c

 flagImage.layer.masksToBounds = YES; 

Swift

 flagImage.layer.masksToBounds = true 
+4
source share

you are only MISS borderWidth = 1 (x)

+1
source share

Made ImageView , say 65w x 65h. Then I dragged another image into the front-end constructor and made it 67wx67h. Then I changed its background to black and moved it after another. This will give the first imageView black border. Just adjust the appearance of the black image to adjust the thickness of the border.

did a gray border in the image, yours would be black

-one
source share

All Articles