I am new to swift and I am trying to set a black border around my UIImageView
but I am unable to do so. 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
}
Could I get some help on this?
To change that, and make the shape view act as a border, all we have to do is to apply a stroke to it, passing as argument the desired color. Text("Borders in SwiftUI!") Text("Borders in SwiftUI!")
UIImage contains the data for an image. UIImageView is a custom view meant to display the UIImage .
For example: UIImage *img = [[UIImage alloc] init]; [img setImage:[UIImage imageNamed:@"anyImageName"]]; My UIImage object is declared in . h file and allocated in init method, I need to set image in viewDidLoad method.
You gave the border color to the imageView but how could you expect to see the color with out any area to fill in. So, the
flagImage.layer.borderWidth = 2 /** as you wish **/
Gives the Area around the imageView of thickness 2 to fill in the color you gave.
Try to add this
Objective-C
flagImage.layer.masksToBounds = YES;
Swift
flagImage.layer.masksToBounds = true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With