I want to show image and title both in a button, then i try the setImageEdgeInsets and setTitleEdgeInsets.But it makes me confused.
Before setting the insets property, the button likes below ( Black rect represent the button bounds, Red rect represent the image rect, Green rect represent the title rect.)
Additional Description: My image's actual size is twice of i useļ¼ which means
** [image size].width = imageWidth * 2 **
then i use setImageEdgeInsets function, to set image rect
[btn setImageEdgeInsets:UIEdgeInsetsMake((btnHeight-titleHeight-imageHeight)/2.0,
(btnWidth-imageWidth)/2,
titleHeight+(btnHeight-titleHeight-imageHeight)/2.0,
(btnWidth-imageWidth)/2)];
Now the button likes this
Then i use setTitleEdgeInsets function, to set title rect
I first think code should be:
[btn setTitleEdgeInsets:UIEdgeInsetsMake(btnHeight-titleHeight, 0, 0, 0)];
but the button in fact likes this
i also try code:
[btn setTitleEdgeInsets:UIEdgeInsetsMake(btnHeight-titleHeight, -imageWidth, 0, 0)];
Button now likes this
Then i try code:
[btn setTitleEdgeInsets:UIEdgeInsetsMake(btnHeight-titleHeight, -imageWidth*2, 0, 0)];
It's effective!
But i'm confused now! why the title's left inset should be negative? and why does it related to image's width?