UIButton title and image alignment query(UIButton标题和图片对齐查询)
问题描述
我有一个 UIButton
,我正在尝试在其上设置标题和图像.
I have a UIButton
and I am trying to set a title and an image on it.
我想将 UIButton
的标题对齐到左侧,并将图像对齐到右侧.我正在尝试在时钟应用程序中获取计时器按钮的外观和感觉(显示计时器结束时"的按钮).
I would like to align the title for a UIButton
to the left side and place an image aligned to the right. I am trying to get the look and feel of the button in Timer in Clocks app (the one which says "When Timer Ends").
我用 contentHorizontalAlignment
、contentEdgeInsets
、titleEdgeInsets
和 imageEdgeInsets
来实现我的目标,但无济于事.同样的文档也很少.
I fiddled with contentHorizontalAlignment
, contentEdgeInsets
, titleEdgeInsets
and imageEdgeInsets
to achieve my goal, but to no avail. The documentation is also quite sparse for the same.
我怎样才能达到同样的效果?
How can I achieve the same?
还有相关的问题,时钟应用程序中的计时器有两组文本,一组与图像左对齐,另一组右对齐?如何在 UIButton
中做到这一点?(虽然目前我不需要该功能).
Also related questions, Timer in Clocks app has two set of Text, one aligned to the left and other aligned right with the image? How can that be done in a UIButton
? ( I do not need that functionality though at the moment).
推荐答案
更改 UIButton
上的 imageEdgeInsets
属性,然后使用 setImage:forState:代码>
Change the imageEdgeInsets
property on the UIButton
and then just use setImage:forState:
这篇关于UIButton标题和图片对齐查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:UIButton标题和图片对齐查询


基础教程推荐
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01