2

I have UIImages that I show in a UIImageView. The UIImageView has the

contentMode = .scaleAspectFit

property. The UIImages show just fine on the UIImageView, but I want to edit the UIImages so that they don't have any blank (transparent) space, and instead fill the blank spaces with a black color, and I want it to do this dynamically, depending on the end-users screen size.

Example:

enter image description here

enter image description here

What I want to do is replace the areas I've drawn in, with a black color, and save it as an UIImage.

Krunal
  • 77,632
  • 48
  • 245
  • 261
Tarek Orfali
  • 73
  • 2
  • 7

3 Answers3

2

Simply set backgroundcolor for the uiimageview

Bjørn Ruthberg
  • 336
  • 1
  • 15
1

Set the background Color of the imageView to black

Using imageView outlet

self.imageView.backgroundColor = UIColor.black

Using IB

Using IB

Community
  • 1
  • 1
Md. Ibrahim Hassan
  • 5,359
  • 1
  • 25
  • 45
1

Set black color for imageview as well as set frame equal to frame of main view.

self.imageView.backgroundColor = UIColor.black


For AutoRisize:

self.imageView.frame = self.view.frame


For AutoLayout:
Set leading, trailing, top and bottom constraints with main view (self.view)

Krunal
  • 77,632
  • 48
  • 245
  • 261