Другой взгляд на iPhone 8 и iPhone X - PullRequest
0 голосов
/ 31 октября 2018

Существует проблема с текстовым представлением, которое было создано программно. На iPhoneX он выскакивает до ~ 20 пикселей, но на iPhone 8 выглядит превосходно. Я буду очень благодарен за любые подсказки :) Прикрепленные скриншоты.

iPhoneX: http://prntscr.com/lcnh2y iPhone 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)

1 Ответ

0 голосов
/ 31 октября 2018

Используйте viewDidLoad для создания и WillLayout для позиционирования. Я не рекомендую смешивать раскадровку и программно создавать пользовательский интерфейс

класс ViewController: 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."
}

}

...