I am trying to create buttons after getting response from a network request. How do I do this and position them after creating them, after the view is loaded. I am also creating my views programmatically and using AutoLayout.
CustomView.swift
class CustomView: UIView {
override init(frame: CGRect) {
super.init(frame: UIScreen.main.bounds)
backgroundColor = .red
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
ViewController.swift
// Load custom view
override func loadView() {
view = CustomView()
}
override func viewDidLoad() {
super.viewDidLoad()
// Create buttons after getting response
viewModel.output.apiOutput
.subscribe(onNext: { posts in
for post in posts {
// create buttons
}
})
.dispose(by: disposeBag)
}