Align button image to right edge of UIButton

前端 未结 14 2269
野趣味
野趣味 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:35

    There are several different options to do it.

    Use semanticContentAttribute

    button.semanticContentAttribute = .forceRightToLeft
    

    You can set semantic attribute from interface (storyboard) layout also.


    or Use UIView containing UIButton and UIImage, as shown in this snapshot.

    • Set Image right side in UIView and disable user interaction, so user action/tap will be passed to button.
    • Add button with size same as UIView, in UIView, with transparent background color and covering Image.
    • Set content offset for button as shown in this snapshot.

    This will make easy to handle button action, properties and customise image position & size according to your requirement. Try this.

提交回复
热议问题