By default, there is no space between the UIButton ImageView and Titlelabel, and two is centered as a whole.
The Titleedgeinsets and imageedgeinsets of the button are not based on the left and right margins of the buttons, but are determined by the current position of the Titlelabel and ImageView.
But in the process of testing, we find problems, such as
CGFloat topMargin = 50;
Self.btnTest.imageEdgeInsets = Uiedgeinsetsmake (topMargin000);
The ImageView position of the button after the operation of our code should be moved down by 50 relative to the previous position, but this is not the case, after several tests (TopMargin takes multiple values), the button's ImageView downward offset (in the state before ImageView ) is always the amount of TOPMARGIN/2.
(This is so strange ...) Finally after thinking ... ^_^ ~, since imageedgeinsets and titleedgeinsets are not relative to the button margin, they are offset relative to the original position. But Uiedgeinsetsmake has four parameters, Top,left,button and right, and the control cannot move up and down at the same time, or move to the left.
Take the following example:
Self.btnTest.imageEdgeInsets = Uiedgeinsetsmake (TopMargin, LeftMargin, Buttommargin, RightMargin);
At this point the offset of the ImageView relative to the original is:
x = (leftmargin-rightmargin)/2;
y = (topmargin-buttommargin)/2;
(measured).
UIButton titleedgeinsets and Imageedgeinsets in iOS