iphone - UIView定位相关问题(iOS)

标签 iphone ios xcode uiview uikit

我有很多问题:

  1. 如何定位 UIView,使其位于我要添加到的 View 的底部?
  2. 如何将 subview 添加到 View 中,以便它位于 super View 的角落,并留有一个小间隙(就像我想要一个“x”十字符号来关闭某些东西)
  3. 它们是一个用于轻松 UIView 定位(和旋转)的实用程序类吗?

任何引用资料、开源教程等都将受到欢迎!

最佳答案

(a) 如何定位 UIView,使其位于我要添加到的 View 的底部?

好吧,假设您要将 button 定位为 View form 底部的 subview ,您计算的 origin.y subview 按钮通过从表单的高度减去按钮的高度

CGRect buttonFrame = button.frame;
buttonFrame.origin.y = form.bounds.size.height - buttonFrame.size.height;
button.frame = buttonFrame;
[form addSubview:button];

您也可以更改原点水平位置。您希望它位于表单的左下角吗?

buttonFrame.origin.x = 0;

或者在表单的右边缘

buttonFrame.origin.x = form.bounds.size.width - buttonFrame.size.width;

或者在表单的中间(水平)?

buttonFrame.origin.x = (form.bounds.size.width - buttonFrame.size.width) / 2;

或使用CGRectGetMidX的其他方式(在 CGGeometry utility methods 中找到):

buttonFrame.origin.x = CGRectGetMidX(form.bounds) - buttonFrame.size.width/2;

当父 View 的大小发生变化时,自动调整大小可以调整框架。但你仍然需要先定位它。

关于iphone - UIView定位相关问题(iOS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15295573/

相关文章:

ios - 如何在 ios 上使用 In App Purchase 在购买(非订阅)之前处理免费试用

ios - 获取 UINavigationBar 的前景色

ios - 标准附件 View 可以位于 UITableViewCell 中的不同位置吗?

swift - 如何将 Swift Cocoapod 中的类导入到 Swift 项目中?

xcode - 错误无法构建 iOS 项目。我们运行了 "xcodebuild"命令,但它以错误代码 65 退出

ios - 如何按数据添加顺序获取核心数据并按该顺序显示在 UITableView 中?

从主屏幕点击应用程序时的 iOS 事件

ios - 从选项卡 Controller 在当前上下文中呈现 Model View Controller 后出现黑屏

iphone - 使用 cocos2D 的 Endless Game 背景的视差滚动

ios - 分享 Gifs Swift