Created
July 23, 2020 11:22
-
-
Save TarasShu/af463df7ba177b15624055409a11b7cb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let frame = CGRect(x: 0, y: 50, width: 50, height: 50) | |
let blueSquare = UIView(frame: frame) | |
blueSquare.backgroundColor = .systemRed | |
view.addSubview(blueSquare) | |
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 height = Int(view.bounds.height) | |
let width = 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 = Int(view.bounds.height / CGFloat(count)) | |
sq.frame = CGRect(x: startOfWidth + ( (width + distance) * i), | |
y: endOfHeight - height , | |
width: basis,// вот тут я не могу понять, почему это мне не выдает height / CGFloat(count). то есть если count 2 я бы хотел чтоб width одного квадрата была половине ширине экрана. а он просто печает два квадрата маленьких слева на право | |
height: height) | |
sq.backgroundColor = .systemYellow | |
squeres.append(sq) | |
} | |
for i in squeres { | |
i.layer.cornerRadius = 0 | |
view.addSubview(i) | |
} | |
} | |
bottom(3) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment