添加具有动态高度的 UIViews iPhone
在我的视图控制器的视图中,我需要添加几个自定义 UIView,我在 loadView 方法中执行此操作,
因此在我的自定义 uiview 的 drawRect 方法中,我添加了几个 UILabel。
在我的视图控制器的视图中,我需要将所有这些自定义 UIView 添加到彼此的下面,但我不知道它们的高度
有时是 20px、40px、60px,具体取决于 drawRect 的结果,
所以当我初始化自定义 UIView 时,我给它一个框架高度可以说是 50.. 但是当绘制矩形完成后,它只有 20、50 太多了,所以我需要调整框架高度,
但是我如何确定自定义 UIView 的可见高度是多少,以及当自定义 uiview 有时我可以在视图控制器中捕获它完成了他的drawRect方法,
是否有某种自动调整大小,我在视图控制器中哪里可以捕获它,这样我就可以将自定义uiview放置在彼此的正下方。
in my viewcontroller's view i need to add a couple of custom UIView's, i do that in the loadView method
so in my custom uiview's drawRect method i add a couple of UILabel's.
in my viewcontroller's view i need to add all those custom UIView's underneath each other but i don't know what their height is
sometimes 20px, 40px, 60px, depending on the outcome of the drawRect
so when i init my custom UIView i give it a frame height of lets say 50..
but when the drawRect is done and it's only 20, 50 is too much so i need to adjust the frame height
but how can i determine what's the visible height of the custom UIView and where can i catch it in my viewcontroller when the custom uiview has finished his drawRect method
is there some kind of autoresize and where do i catch it in my viewcontroller, so i can position the custom uiview right under neath each other.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
考虑使用 UIView 的 tag 属性作为在执行 drawRect 后访问动态创建的视图的方式。此时,您应该能够通过访问视图的frame.size.height 来获取动态创建的视图的高度。使用此功能可以将它们按照您的需要堆叠在一起。
如果您提供您正在做的事情的代码示例,我或其他人可以为您提供更具体的帮助。
巴特
Consider using the tag property of UIView as a way to access your dynamically created views after drawRect has executed. At this point you should be able to get the height of the dynamically created views by accessing the frame.size.height of the view. Use this to position them to be stacked on top of each other as you desire.
If you provide code samples of what you're doing I or other people can give you more specific assistance.
Bart