Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'imageEdgeInsets' was deprecated in iOS 15.0

Tags:

ios

swift

I'm getting the warning:

'imageEdgeInsets' was deprecated in iOS 15.0

When setting UIButton imageEdgeInsets like so:

button.imageEdgeInsets = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)

I tried setting imageEdgeInsets like so:

UIImage(named: "filter")?.withRenderingMode(.alwaysTemplate).withAlignmentRectInsets(UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10))

Both where top, left, right and bottom are positive or negative values, no luck. Anyone who knows the version of

imageEdgeInsets

That's not deprecated in iOS 15? All help is appreciated, Kind regards :)

like image 474
Johan Albrectsen Avatar asked Jul 10 '21 13:07

Johan Albrectsen


1 Answers

iOS 15 Apple introduced 3 new options to control padding and insets.

  1. .titlePadding : Padding between the title and subtitle labels.
  2. .imagePadding : Padding between the button’s image and text.
  3. .contentInsets: Padding from the button’s content area to its bounds.

Using the above option you can manage and set your button style according.

enter image description here

You can check this article for more. Source and Image

So your code should be like this

var configuration = UIButton.Configuration.filled()
configuration.title = "Title"
configuration.image = UIImage(systemName: "swift")
configuration.titlePadding = 10
configuration.imagePadding = 10
configuration.contentInsets = NSDirectionalEdgeInsets(top: 10, leading: 10, bottom: 10, trailing: 10)
like image 66
Raja Kishan Avatar answered Sep 24 '22 04:09

Raja Kishan