Just found on the Web property Settings button content on the image under the title in UIButton there are three settings for Edgeinsets: Contentedgeinsets, titleedgeinsets, Imageedgeinsets@property (nonatomic) uiedgeinsets contentedgeinsets ui_appearance_selector;//default is Uiedgeinsetszero /c1>@property (nonatomic) uiedgeinsets titleedgeinsets; Default is Uiedgeinsetszero@property (nonatomic) BOOL reversestitleshadowwhenhighlighted;//default is NO. If YES, shadow reverses to shift between engrave and emboss appearance@property (nonatomic) uiedgeinsets imageedgeinsets; Default is Uiedgeinsetszero typedef struct Uiedgeinsets { cgfloat top, left, bottom, right; //Specify amount to inset (positive) for each of the edges. Values can is negative to ' outset ' } The four parameters inside the uiuiedgeinsetsmake represent distances from the top, left, bottom, and right boundaries, which are zero by default. Title/image in the center of the button [OBJC] uikit_static_inline uiedgeinsets uiedgeinsetsmake (cgfloat top, CGFloat left, CGFloat Bottom, cgfloat right) { uiedgeinsets insets = {top, left, bottom, right}; return insets; } button.imageedgeinsets = Uiedgeinsetsmake (5,13,21, Button.titleLabel.bounds.size.width);//Set the position of the image on the button (top, left, bottom bottom, right) here can write negative values, write to 5, Then image is like moving up 5 pixels button.titleedgeinsets = Uiedgeinsetsmake (-button.titlelabel.bounds.size.width-50, 0, 0);//Set the title position on the button (top, left, bottom bottom, right) // Button.contEnthorizontalalignment = uicontrolcontenthorizontalalignmentcenter;//The contents of the button are centered horizontally ... Set content is title and image change together & nbsp
iOS changes the button's image and title position according to Uiedgeinsets