UIButton Image
On UIButton, by default, the picture is in the left text on the right, and in most cases, the default display format cannot meet our needs. Next I will share my experiences on this issue.
By default, the effects that are not set are centered.
UIButton * button = [UIButton buttonWithType: UIButtonTypeCustom];
Button. frame = CGRectMake (50, 50,150,100 );
Button. backgroundColor = [UIColor yellowColor];
[Button setTitleColor: [UIColor blackColor] forState: UIControlStateNormal];
[Button setTitle: @ "title" forState: UIControlStateNormal];
[Button setImage: [UIImage imageNamed: @ "tab5"] forState: UIControlStateNormal];
[Self. view addSubview: button];
**************************************** *****************
UIEdgeInsetsMake (CGFloat top, CGFloat left, CGFloat bottom, CGFloat right );
The above four values are changed based on the original position, for example:
[Button setTitleEdgeInsets: UIEdgeInsetsMake (0, 0, 0, 60)];
[Button setImageEdgeInsets: UIEdgeInsetsMake (0, 60, 0, 0)];
The change of CGFloat right in title 60 is based on the right Border of titleLabel in the original position, which is the distance from the left border to the right border.
The same is true for images. The left border of the original imageView is shifted to 60 to the right.
**************************************** *****************
[Button setTitleEdgeInsets: UIEdgeInsetsMake (30, 0, 0, 30)];
[Button setImageEdgeInsets: UIEdgeInsetsMake (0, 30, 30, 0)];
The principle of up and down movement is the same as that of the left and right sides;
**************************************** *******
* Note: The displacement of the four values is based on the original position, for example *
* A number is to move downward based on the position of the original upper border, and a positive number moves downward to a negative number *
* Move up. The same applies to the left and right sides ;*
**************************************** *******