I am creating scrollView programmatically, but for some reasons i can see the scrollView's scroll bar but the subViews aren't scrolling. Have added my codes below
//create a closure for scroll view
let vcScrollView: UIScrollView = {
let scrollView = UIScrollView()
scrollView.translatesAutoresizingMaskIntoConstraints = false
scrollView.backgroundColor = UIColor.dark_background
return scrollView
}()
//create closure for dark view
let darkView: UIView = {
let view = UIView()
view.backgroundColor = UIColor.black
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
//create a closure for offer label
let offerLabel: UILabel = {
let label = UILabel()
label.translatesAutoresizingMaskIntoConstraints = false
label.textColor = UIColor.white
return label
}()
override func viewDidLoad() {
super.viewDidLoad()
modalPresentationCapturesStatusBarAppearance = true
view.addSubview(vcScrollView)
setUpViews()
}
func setUpViews(){
//scrollView
vcScrollView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
vcScrollView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
vcScrollView.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
vcScrollView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
vcScrollView.contentSize.height = 1500
//Dark view
vcScrollView.addSubview(darkView)
darkView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
darkView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
darkView.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
darkView.heightAnchor.constraint(equalToConstant: 130).isActive = true
//Offer Label
darkView.addSubview(offerLabel)
offerLabel.text = selectedOffer
offerLabel.font = UIFont(name: String.defaultFontR, size: 29)
offerLabel.textAlignment = .center
offerLabel.topAnchor.constraint(equalTo: darkView.topAnchor, constant: 95).isActive = true
offerLabel.leadingAnchor.constraint(equalTo: darkView.leadingAnchor, constant: 20).isActive = true
offerLabel.trailingAnchor.constraint(equalTo: darkView.trailingAnchor, constant: -20).isActive = true
}
Have added the scroll view as a subView for the view too. Thanks in advance