В зависимости от размера экрана, замените
let newView = UIView(frame: CGRect(x: 0, y: 0, width: 380, height: 100))
на
let newView = UIView(frame: CGRect(x: 0, y: 0, width:view.frame.width - 40.0, height: 100))
. Лучше
newView.translatesAutoresizingMaskIntoConstraints = false
viewTest.addSubview(newView)
NSLayoutConstraint.activate([
newView.centerYAnchor.constraint(equalTo:viewTest.centerYAnchor),
newView.rightAnchor.constraint(equalTo:viewTest.rightAnchor,constant:-10),
newView.leftAnchor.constraint(equalTo: viewTest.leftAnchor,constant:10),
newView.heightAnchor.constraint(equalToConstant:100)
])
Для исправления кадров доступа вид должен быть внутри viewDidLayoutSubviews
, а не viewDidLoad