Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 单独图像';从标题到位置';UIS按钮上的长度_Ios_Objective C_Uiimageview_Uibutton_Uiimage - Fatal编程技术网

Ios 单独图像';从标题到位置';UIS按钮上的长度

Ios 单独图像';从标题到位置';UIS按钮上的长度,ios,objective-c,uiimageview,uibutton,uiimage,Ios,Objective C,Uiimageview,Uibutton,Uiimage,UIButton图像位置取决于同一图像的当前标题长度 如果没有标题集,则第一个UIButton图像居中。 当有一个时,第二个会向左移动(“like”) 如何始终将UIButton图像保持在按钮的中心?即使标题出现在它的顶部 我已经试过imageInset了,也是同样的问题。我也不想使用默认UIButton之外的其他UIImageView。您可以使用以下代码 // the space between the image and text CGFloat spacing = 6.0; // l

UIButton图像位置取决于同一图像的当前标题长度

如果没有标题集,则第一个UIButton图像居中。 当有一个时,第二个会向左移动(“like”)

如何始终将UIButton图像保持在按钮的中心?即使标题出现在它的顶部


我已经试过imageInset了,也是同样的问题。我也不想使用默认UIButton之外的其他UIImageView。

您可以使用以下代码

// the space between the image and text
CGFloat spacing = 6.0;

// lower the text and push it left so it appears centered 
//  below the image
CGSize imageSize = button.imageView.frame.size;
button.titleEdgeInsets = UIEdgeInsetsMake(
  0.0, - imageSize.width, - (imageSize.height + spacing), 0.0);

// raise the image and push it right so it appears centered
//  above the text
CGSize titleSize = button.titleLabel.frame.size;
button.imageEdgeInsets = UIEdgeInsetsMake(
  - (titleSize.height + spacing), 0.0, 0.0, - titleSize.width);
资料来源:

您可以使用下面的链接尝试其他解决方案


希望它能帮助您……

您可以分别调整图像和标题的边缘插入。Interface Builder上有一个下拉菜单名“Edge”,允许您在“内容”、“标题”和“图像”之间切换。我已经试过了。谢谢,但这不是重点。我的按钮的标题在单击时更改。所以我的优势应该是动态性,我不想这样。我正在寻找一种简单的方法来分离图像帧和标题标签帧。如果有的话。