如何将 UIActivityIndi​​catorView 与文本(UILabel)一起居中?

发布于 2024-09-30 08:51:53 字数 260 浏览 1 评论 0原文

我现在在 iPhone 开发中已经多次遇到这个问题,但尚未找到好的解决方案。我正在寻找的是这样的:

我想显示一些文本和图标,并且我希望整体显示在其父视图中居中。具体来说,在我当前的情况下,我希望显示一个显示“正在重新连接...”的框,并在文本左侧显示一个 UIActivityIndi​​catorView。

以前,我只是依靠这样一个事实:我确切地知道文本和活动指示器的尺寸,因此我可以将事物绝对放置在中心位置。我正在寻找的是更自动化的东西。

有什么想法吗?

I've had this issue come up a couple times doing iPhone development now and have yet to find a good solution for it. What I'm looking for is this:

I want to show some text along with an icon and I want the overall display to be centered within its parent view. Specifically, in my current case, I'm looking to display a box that says "Reconnecting..." with a UIActivityIndicatorView to the left of the text.

Previously, I've just relied on the fact that I know exactly the dimensions of the text and activity indicator, so I can position things absolutely to appear centered. What I'm looking for is something more automatic.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

黯然 2024-10-07 08:51:53

UIKit 添加到 NSString 之一 如果您为 UILabel 提供了正在使用的字体,则将返回文本的像素大小。因此,您描述的布局中这两件事的总大小大概是:

  • label.frame.origin.x 和 ActivityIndi​​catorView.frame.origin.x 之间的差异;加上
  • 文本的宽度。

然后,您可以适当地打乱两个视图,或者给它们一个共同的父视图,该父视图仍然是整个视图的子视图并进行移动。

One of the UIKit additions to NSString will return the pixel size of the text if you give it the font that you're using on the UILabel. So then presumably the total size of the two things together in the layout you describe is:

  • the difference between label.frame.origin.x and activityIndicatorView.frame.origin.x; plus
  • the width of the text.

You can then either shuffle both the views appropriately or give them a common parent that's still a subview of the whole thing and shift that.

春庭雪 2024-10-07 08:51:53

只需调用单个方法即可在视图中显示活动指示器。请单击 这里获取SHKActivityIndi​​cator类

An activity indicator can be shown in a view just calling a single method.Please click here get SHKActivityIndicator class

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文