UIButton设置image上下左右位置 swift

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
 }

 

posted @ 2024-05-29 09:18  黄增松  阅读(35)  评论(0编辑  收藏  举报