iOS15:比較簡單了(蘋果為啥到了iOS15才想起來按鈕還需要這個功能呢)。Button新增UIButton.Configuration用來配置
if #available(iOS 15.0, *) { var config = UIButton.Configuration.plain() ///這裡imagePlacement圖片的位置 .leading .trailing .bottom .top config.imagePlacement = .top config.imagePadding = 10 config.image = UIImage(named: "imgname") testButton.configuration = config }