ios调节Button中image的位置和title的位置

button.imageEdgeInsets = UIEdgeInsetsMake(0,titleSize.width + interval, 0, -(titleSize.width + interval));

button.titleEdgeInsets = UIEdgeInsetsMake(0, -(imageSize.width + interval), 0, imageSize.width + interval);


button.titleLabel.backgroundColor = button.backgroundColor;

button.imageView.backgroundColor = button.backgroundColor;

//在使用一次titleLabel和imageView后才能正确获取titleSize

CGSize titleSize = button.titleLabel.bounds.size;

CGSize imageSize = button.imageView.bounds.size;

CGFloat interval = 1.0;

button.imageEdgeInsets = UIEdgeInsetsMake(0,titleSize.width + interval, 0, -(titleSize.width + interval));

button.titleEdgeInsets = UIEdgeInsetsMake(0, -(imageSize.width + interval), 0, imageSize.width + interval);



button.titleLabel.backgroundColor = button.backgroundColor;

button.imageView.backgroundColor = button.backgroundColor;

CGSize titleSize = button.titleLabel.bounds.size;

CGSize imageSize = button.imageView.bounds.size;

CGFloat interval = 1.0;

[button setImageEdgeInsets:UIEdgeInsetsMake(0,0, titleSize.height + interval, -(titleSize.width + interval))];

[button setTitleEdgeInsets:UIEdgeInsetsMake(imageSize.height + interval, -(imageSize.width + interval), 0, 0)];

你可能感兴趣的:(ios调节Button中image的位置和title的位置)