简体   繁体   English

使UIButton居中,旁边有图像

[英]Center UIButton with image next to it

I'm trying to create a UIButton where the facebook icon is a part of the centering, however i can't seem to figure out how to make it part of the centering process. 我正在尝试创建一个UIButton,其中Facebook图标是居中的一部分,但是我似乎无法弄清楚如何使其成为居中过程的一部分。 So far i've just created a UIButton with the text. 到目前为止,我刚刚创建了带有文本的UIButton。 I could just create a image next to it, however then it will not be part of the centering. 我可以在其旁边创建一个图像,但是它不会成为居中的一部分。

在此处输入图片说明

You can easily set image and title both for your button for different control state like normal,selected or highlighted etc . 您可以轻松地为按钮的图像和标题设置不同的控制状态,例如normal,selected or highlighted etc

So, set your image and title to your button from storyboard or programmatically there is no need to take separate imageview for image. 因此,从情节提要中将图像和标题设置为按钮,或者以编程方式无需为图像获取单独的imageview

You can set edge insets for title and image both from interface builder or programmatically. 您可以从界面构建器或以编程方式设置titleimage edge insets you can manage top or bottom edge insets for title and image of button to manage it's vertical appearance! 您可以管理按钮标题和图像的上边缘top or bottom边缘插图,以管理按钮的垂直外观!

check screen shot below, 检查下面的屏幕截图,

在此处输入图片说明

Update : (as asked in comment) 更新:(按评论要求)

For example, 例如,

在此处输入图片说明

this is the setup for my back button with image! 这是带有图像的后退按钮的设置!

Provide button title and image for normal state. 提供正常状态下的按钮标题和图像。 Then just change the left inset for image as per image 然后只需根据图像更改图像的左插图

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM