如何将 UIActivityIndicatorView 与文本(UILabel)一起居中?
我现在在 iPhone 开发中已经多次遇到这个问题,但尚未找到好的解决方案。我正在寻找的是这样的:
我想显示一些文本和图标,并且我希望整体显示在其父视图中居中。具体来说,在我当前的情况下,我希望显示一个显示“正在重新连接...”的框,并在文本左侧显示一个 UIActivityIndicatorView。
以前,我只是依靠这样一个事实:我确切地知道文本和活动指示器的尺寸,因此我可以将事物绝对放置在中心位置。我正在寻找的是更自动化的东西。
有什么想法吗?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
UIKit 添加到 NSString 之一 如果您为 UILabel 提供了正在使用的字体,则将返回文本的像素大小。因此,您描述的布局中这两件事的总大小大概是:
然后,您可以适当地打乱两个视图,或者给它们一个共同的父视图,该父视图仍然是整个视图的子视图并进行移动。
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:
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.
只需调用单个方法即可在视图中显示活动指示器。请单击 这里获取SHKActivityIndicator类
An activity indicator can be shown in a view just calling a single method.Please click here get SHKActivityIndicator class