이거때문에 3시간은 날린듯...
UIButton에서 이미지를 조절하는 방법은 과거에는 contentInset같이 Inset을 조절하여 이미지 사이즈를 조절하는 방식이 있었지만, 지금은 업데이트 되면서 빠지게 되었다. 그래서 다른 방식으로 이미지를 조절해야 한다.
그 방법은 이미지 사이즈 자체를 조절하는 것.
UIButton는 이미지의 크기대로 버튼 내부에 그릴 뿐. 따라서 image를 내가 원하는 사이즈로 resizing하면 된다.
이미지 리사이징 코드
import UIKit
extension UIImage {
    func resizeImageTo(size: CGSize) -> UIImage? {
        UIGraphicsBeginImageContextWithOptions(size, false, 0.0)
        self.draw(in: CGRect(origin: CGPoint.zero, size: size))
        guard let resizedImage = UIGraphicsGetImageFromCurrentImageContext() else {
            return nil
        }
        UIGraphicsEndImageContext()
        return resizedImage
    }
}
버튼에 적용
 var nextButton: UIButton = {
        let button = UIButton()
        button.translatesAutoresizingMaskIntoConstraints = false
        let image = UIImage(systemName: "chevron.forward")?.resizeImageTo(size: CGSize(width: 20, height: 30))
        button.setImage(image, for: .normal)
        button.tintColor = .black
        
        return button
    }()

이 방법 말고도 configuration을 이용해서 조절하는 방법이 있다.
lazy var buttonConfiguration: UIButton.Configuration = {
        var config = UIButton.Configuration.plain()
        var imageConfig = UIImage.SymbolConfiguration(pointSize: 20)
        config.preferredSymbolConfigurationForImage = imageConfig
        return config
    }()
lazy var beforeButton: UIButton = {
        let button = UIButton(configuration: buttonConfiguration)
        button.configuration?.image = UIImage(systemName: "chevron.left")
        button.tintColor = .black
        
        return button
    }()
다만 이 방식은 padding에 의해 이미지의 사이즈에 따라 버튼의 크기 자체가 변하므로 나는 윗부분인 이미지 사이즈를 리사이즈 하는 방식이 더 편한것 같다..
https://sarunw.com/posts/new-way-to-style-uibutton-in-ios15/
A new way to style UIButton with UIButton.Configuration in iOS 15 | Sarunw
The first part in the series "What's new in UIKit button". An introduction to a new button configuration, a struct that is shaping and styling your button. You no longer need to subclass UIButton ever again with button configuration.
sarunw.com