gpt4 book ai didi

ios - iPhone 8 和 iPhone X 的不同视角

转载 作者:行者123 更新时间:2023-11-28 07:37:01 24 4
gpt4 key购买 nike

以编程方式创建的 TextView 存在问题。它在 iPhoneX 上弹出大约 20px,但在 iPhone 8 上看起来很完美。我将非常感谢任何提示 :) 附上屏幕截图。

iPhoneX: http://prntscr.com/lcnh2yiPhone 8: http://prntscr.com/lcnhns

代码:

let rect = CGRect(x: 20, y: self.tabsSegmentedControl.layer.position.y + 20, width: self.tabsSegmentedControl.layer.frame.width, height: 127)
self.ingredientsTextView = UITextView(frame: rect)
ingredientsTextView.isEditable = false
ingredientsTextView.isSelectable = false
self.view.addSubview(ingredientsTextView)

最佳答案

使用 viewDidLoad 进行创建,使用 WillLayout 进行定位。我不建议混合使用 Storyboard 和以编程方式创建 UI

类 View Controller :UIViewController {

@IBOutlet weak var tabsSegmentedControl: UISegmentedControl!

var ingredientsTextView : UITextView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
ingredientsTextView = UITextView(frame: .zero)
self.view.addSubview(ingredientsTextView)
ingredientsTextView.isEditable = false
ingredientsTextView.isSelectable = false
}

override func viewWillLayoutSubviews() {
let rect = CGRect(x: 20, y: self.tabsSegmentedControl.frame.maxY + 20, width: self.tabsSegmentedControl.frame.width, height: 127)
ingredientsTextView.frame = rect
ingredientsTextView.text = "There is a problem with the text view that's been programmatically created. It just pops up to ~20px at iPhoneX, but looks perfect at iPhone 8. I'll be super grateful for any hints :) Screenshots attached."
}

关于ios - iPhone 8 和 iPhone X 的不同视角,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53082821/

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