Skip to content

Instantly share code, notes, and snippets.

class ViewController: UIViewController, UIScrollViewDelegate {
let scrollView = UIScrollView()
// let scroll = UIView()
override func viewDidLoad() {
super.viewDidLoad()
view = scrollView
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)
var scrollViewVertical = UIScrollView() // внимание
var firstView = UIView()
let lable = UILabel()
var scrollViewVerticalFrame: UIView // и тут
func squareVertical(_ count: Int) {
for i in 0..<count{
let sq = UIView()
let x = sq.frame.maxX
let color: [UIColor] = [.systemRed,
.systemYellow,
.systemBlue,
.systemGray,
.systemPink,
.systemGray2]
var colotOfFirstView = UIColor()
if firstView.bounds == lable.bounds
{
colotOfFirstView = .systemRed
} else {
colotOfFirstView = .systemYellow
}
firstView.backgroundColor = colotOfFirstView
lable.backgroundColor = .systemRed
func hackerSpeak(_ str: String) -> String {
var stt = [Character]()
var result = [Character]()
for Character in str{
stt.append(Character)
}
func filterStateNames(_ arr: [String], _ type: String) -> [String] {
if type != "abb" {
return arr.filter({$0.count > 2})
}
if type != "full" {
return arr.filter({$0.count < 2})
func isStrangePair(_ str1: String, _ str2: String) -> Bool {
if str1.index(after: str1.startIndex) == str2.index(before: str2.endIndex)
&&
str1.index(before: str1.endIndex) == str2.index(after: str2.startIndex)
{
return true
lass myViewController: UIViewController{
@IBOutlet weak var viewForLayer: UIView!
var layer: CALayer {
return viewForLayer.layer
}
func setUpLayer() {
func bullet1( count: Int) -> [CALayer]{
let bul = [CALayer]()
// let distance = 10
for i in 0...count {
let layer = CALayer()
layer.backgroundColor = CGColor(srgbRed: 0.8, green: 0.2, blue: 0.8, alpha: 1.0)
layer.frame = CGRect(x: 250 ,
y: 150 + (i * count),