Align button image to right edge of UIButton

前端 未结 14 2258
野趣味
野趣味 2020-12-07 23:05

There are plenty of threads about aligning a button image according to the title text, but I can\'t find anything about just aligning the image to the right side of the butt

14条回答
  •  盖世英雄少女心
    2020-12-07 23:51

    make it as default semantic i.e unspecified or force left to right

    and in button.imageEdgeInsets set it as

    UIEdgeInsets(top: 0, left: self.view.frame.size.width - (the image size + the alignment space ) , bottom: 0, right: 0)

    this will make ensure that no matter what the view size is ,it will always align the image from right side of the button

提交回复
热议问题