我想在两行文本的左边放置一个图标,这样在图像和文本开头之间就有2-3个像素的空间.控件本身水平居中对齐(通过Interface Builder设置)
该按钮类似如下所示:
| |
|[Image] Add To |
| Favorites |
我正在try 使用contentEdgeInset、imageEdgeInsets和titleEdgeInsets配置它,但无济于事.我知道负值会扩大边缘,而正值会缩小边缘以使其更接近中心.
我试过:
[button setTitleEdgeInsets:UIEdgeInsetsMake(0, -image.size.width, 0, 0)];
[button setImageEdgeInsets:UIEdgeInsetsMake(0, button.titleLabel.bounds.size.width, 0, 0)];
但是这不能正确显示它.我一直在调整这些值,但是假设从左边的-5到-10,插入值似乎没有以预期的方式移动.-10会将文本一直移到左侧,所以我预计会从左侧移到一半,但事实并非如此.
插图背后的逻辑是什么?我不熟悉图像放置和相关术语.
我用这个SO问题作为参考,但我的价值观有些地方不正确. UIButton: how to center an image and a text using imageEdgeInsets and titleEdgeInsets?个