Created
November 6, 2021 19:24
-
-
Save richardwei6/753f77e58a831091e53b6d743374ecca to your computer and use it in GitHub Desktop.
Coding Club Workshop Code 1
This file contains 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
// | |
// ViewController.swift | |
// iOSWorkshop | |
// | |
// Created by Richard Wei on 11/6/21. | |
// | |
import UIKit | |
class ViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Do any additional setup after loading the view. | |
self.view.backgroundColor = .black; | |
print("Screen width = \(self.view.frame.width)") | |
print("Screen height = \(self.view.frame.height)") | |
let screenWidth : CGFloat = self.view.frame.width; | |
let screenHeight : CGFloat = self.view.frame.height; | |
/* | |
let vSize = 100; | |
let vFrame = CGRect(x: Int(screenWidth)/2 - vSize/2, y: Int(screenHeight)/2 - vSize/2, width: vSize, height: vSize); | |
let v = UIView(frame: vFrame); | |
v.backgroundColor = .systemRed; | |
self.view.addSubview(v); | |
// | |
let titleLabelFrame = CGRect(x: Int(screenWidth)/2 - vSize/2, y: Int(screenHeight)/2, width: vSize, height: vSize); | |
let titleLabel = UILabel(frame: titleLabelFrame); | |
titleLabel.text = "Hello!" | |
titleLabel.textColor = .black; | |
titleLabel.textAlignment = .center; | |
titleLabel.font = UIFont(name: titleLabel.font.fontName, size: self.view.frame.width * 0.05); | |
self.view.addSubview(titleLabel); | |
// | |
let imageViewSize = 100; | |
let imageViewFrame = CGRect(x: Int(screenWidth) / 2 - imageViewSize / 2, y: 100, width: imageViewSize, height: imageViewSize); | |
let imageView = UIImageView(frame: imageViewFrame); | |
imageView.image = UIImage(systemName: "iphone") | |
imageView.tintColor = .black | |
//imageView.backgroundColor = .green; | |
self.view.addSubview(imageView);*/ | |
// | |
let buttonSize = 100; | |
let buttonFrame = CGRect(x: Int(screenWidth)/2 - buttonSize/2, y: Int(screenHeight)/2 - buttonSize/2, width: buttonSize, height: buttonSize); | |
let button = UIButton(frame: buttonFrame); | |
button.backgroundColor = .systemGreen; | |
button.setTitle("Button", for: .normal); | |
button.setTitleColor(.white, for: .normal); | |
//button.tag = -1; | |
button.addTarget(self, action: #selector(handleButtonPress), for: .touchUpInside); | |
button.layer.cornerRadius = 5; | |
self.view.addSubview(button); | |
// | |
} | |
@objc func handleButtonPress(twobutton: UIButton){ | |
print("hello - \(twobutton.tag)") | |
let page2VC = page2ViewController(); | |
page2VC.modalTransitionStyle = .crossDissolve; | |
page2VC.modalPresentationStyle = .fullScreen; | |
self.present(page2VC, animated: true); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment