例如,假设我有一个想要显示的UIView
view.addSubview(line)
现在我希望能够在右上角显示UIView。让我们说在导航栏的右侧。我该怎么做?甚至在特定的地方。
答案 0 :(得分:0)
为子视图添加框架,如下:
<强>目标-C:强>
line.frame = CGRectMake(0, 0, 50, 50);
斯威夫特3:
CGRect(x:0,y:0,width: 50,height: 50)
这将在左上角添加您的线子视图,高度为50,宽度为50。
答案 1 :(得分:0)
您可以使用
$class = 'One\Ting\ming';
strtolower(str_replace("\\", DIRECTORY_SEPARATOR, trim($class, "\\"))).".php";
在navigationBar右侧设置视图。
您还可以在self.navigationController?.navigationItem.rightBarButtonItem = UIBarButtonItem(customView: lineMat)
lineMat
视图
只需使用UIApplication.shared.keyWindow
并设置为UIApplication.shared.keyWindow?.addSubview(lineMat)
视图的框架。
答案 2 :(得分:0)
您需要计算框架或需要为该视图提供约束。
let screenSize = UIScreen.main.bounds
let screenWidth = screenSize.width
let screenHeight = screenSize.height
从上面你可以获得屏幕宽度,你可以将你的y设置为0.假设视图的宽度高度为20.因此,框架将如下所示。
yourView.frame = CGRect(x:screenwidth - 20 , y: 20, width:20 , height: 20)
您可以根据自己的要求更改框架。
对于导航栏,有一种更好的方法可以通过添加正确的条形项来实现。看下面的代码如何做。
self.navigationItem.rightBarButtonItem = rightButtonItem