Skip to content

Instantly share code, notes, and snippets.

@TarasShu
Created July 26, 2020 12:47
Show Gist options
  • Save TarasShu/e882d29e989ff35dbd108d01ac77a8aa to your computer and use it in GitHub Desktop.
Save TarasShu/e882d29e989ff35dbd108d01ac77a8aa to your computer and use it in GitHub Desktop.
class ViewController: UIViewController, UIScrollViewDelegate {
let scrollView = UIScrollView()
// let scroll = UIView()
override func viewDidLoad() {
super.viewDidLoad()
view = scrollView
view = scrollView
scrollView.delegate = self
scrollView.backgroundColor = .white
// scrollView.addSubview(scroll)
//scroll.backgroundColor = .systemRed
//scroll.frame = CGRect(x: 50, y: 50, width: 100, height: 100)
//scroll.backgroundColor = .systemTeal
// scroll.frame = CGRect(x: 300, y: 200, width: 50, height: 50)
scrollView.contentSize.height = 1000
scrollView.contentSize.width = 0
scrollView.alwaysBounceVertical = true
scrollView.alwaysBounceHorizontal = true
let frame = CGRect(x: 0, y: 50, width: 100, height: 100)
let blueSquare = UIView(frame: frame)
blueSquare.backgroundColor = .systemBlue
scrollView.addSubview(blueSquare)
let startOfWidth = Int(scrollView.bounds.minX)
let endOfwidth = Int(scrollView.bounds.maxX)
let startOfHeight = Int(scrollView.bounds.minY)
let endOfHeight = Int(scrollView.bounds.maxY)
let boundsHeight = Int(scrollView.bounds.height)
let boundsWidth = Int(scrollView.bounds.width)
//
// let startOfWidth = Int(view.bounds.minX)
// let endOfwidth = Int(view.bounds.maxX)
// let startOfHeight = Int(view.bounds.minY)
// let endOfHeight = Int(view.bounds.maxY)
//
// let boundsHeight = Int(view.bounds.height)
// let boundsWidth = Int(view.bounds.width)
func bottom(_ count: Int) { // почему может не работать эта функция?
var squeres = [UIView]()
for i in 0..<count{
let sq = UIView()
let height = 50
let distance = 1
let basis = boundsWidth / count
sq.frame = CGRect(x: startOfWidth + ( (basis + distance) * i),
y: endOfHeight - height ,
width: basis,
height: height)
sq.backgroundColor = .tertiarySystemFill
squeres.append(sq)
}
for i in squeres {
scrollView.addSubview(i)
}
}
bottom(5)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment