gpt4 book ai didi

ios - 如何使用 swift 使标签在 subview 中居中

转载 作者:行者123 更新时间:2023-11-30 13:34:38 25 4
gpt4 key购买 nike

我尝试使用 uipresentationcontroller api View 中提供的报价来呈现报价,但它不起作用。我究竟做错了什么?另外,如何动态调整呈现的 View 大小以适应文本?谢谢。

这是我的代码:

override func presentationTransitionWillBegin() {

presentedView()!.layer.cornerRadius = 15.0

//adding label for quote to the presented view
let label = UILabel(frame: CGRectMake(presentedView()!.frame.origin.x, presentedView()!.frame.origin.y, presentedView()!.bounds.width, presentedView()!.bounds.height))
label.center = presentedView()!.center
label.textAlignment = NSTextAlignment.Center
label.text = readQuotesFromLibrary()
presentedView()?.addSubview(label)
//rest of the code dealing with uipresentationcontroller goes here ...

As you can see the text is off}

最佳答案

如果您将呈现 View 的框架分配给标签,那么为什么需要将呈现 View 的中心分配给标签中心。标签将被绘制为呈现 View 的框架。

关于ios - 如何使用 swift 使标签在 subview 中居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36220501/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com