-
Notifications
You must be signed in to change notification settings - Fork 0
/
Basic.swift
executable file
·111 lines (99 loc) · 4.39 KB
/
Basic.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// custom label
X.layer.borderWidth = 5
X.layer.borderColor = UIColor.brown.cgColor
//custom border cicle
X.layer.cornerRadius = 10
//custom background inside
X.clipsToBounds = true
//change font label
X.font = UIFont(name: "X", size: X)
// Make cricle label
lbl_customP2_1.layer.cornerRadius = lbl_customP2_1.frame.size.width / 2 //hinnh vuong => hinh tron
// meg center
lbl_customP2_1.textAlignment = .center
// text flied part 1
txt_demo.isSecureTextEntry = false // turn off securetext entry
txt_demo.keyboardType = .numberPad //appear key board type
txt_demo.placeholder = "🦊hello friend "// set placeholder
// viet tat cua cac kieu dang
label = lbl
textfiled = txt
image view = igm
//img view
img_change.image = UIImage(named: "Turtwig-–-Tổng-quan-về-Pokemon-Turtwig")
img_cricle.layer.cornerRadius = img_cricle.frame.size.width / 2
img_cricle.clipsToBounds = true
img_cricle.contentMode = UIImageView.ContentMode.scaleAspectFit
img_border.layer.borderWidth = 3
img_border.layer.borderColor = UIColor.yellow.cgColor
//Lay anh tu internet
let url:URL = URL (string: "https://luuly1979.files.wordpress.com/2011/03/world-map-background-390622.jpg")!
//Luu y:
//Co https,co duoi la jpg hoac,...
do
{
let dulieu:Data = try Data(contentsOf: url)
imgHinh.image = UIImage(data: dulieu)
}
catch
{
print("khong lay duoc du lieu")
}
// doi voi http can :
//chay vao stackoverflow lay code
//down hinh
//lam y nhu tren
//doi link
//vao info.plist
//paste code vao
//link video https://www.youtube.com/watch?v=aaYtEVBpklk&index=20&list=PLzrVYRai0riSlAocQR3BvHCtEhcKa204E
//AlertcController
let alert:UIAlertController = UIAlertController(title: "Thông Báo" , message:"Xin chào Các Bạn" , preferredStyle: UIAlertController.Style.alert)
let btnOK:UIAlertAction = UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: nil)
alert.addAction(btnOK)
present(alert, animated: true, completion: nil)
//chèn phím
let alert:UIAlertController = UIAlertController(title: "Thông Báo", message: "Vui lòng ", preferredStyle: UIAlertController.Style.alert)
let btnHello:UIAlertAction = UIAlertAction(title: "Hello", style: UIAlertAction.Style.destructive) { (btn) in
print("hello everyone")
}
let btnXinChao:UIAlertAction = UIAlertAction(title: "Xin chao", style: UIAlertAction.Style.cancel) { (btn) in
print("Xin chào các bạn")
}
//chen textfield vao alert
override func viewDidAppear(_ animated: Bool) // hàm chạy sau khi view đid load chạy
alert.addTextField(configurationHandler: nil)//Add textfield to alert
//lấy giá trị từ textfield in ra
btnOK:UIAlertAction = UIAlertAction(title: "OK", style: UIAlertAction.Style.default) { (btnOK) in
let emai:String = alert.textFields![0].text!
let pass:String = alert.textFields![1].text!
print(emai,pass)
}
//co 2 cach de lay gia tri tu slider
1 print(sldValue.value)
2 print(sender.value)
if let sw = sender as? UISwitch // kiem tra ton tai
//web kit
import UIKit
import WebKit // them webkit
class ViewController: UIViewController {
@IBOutlet weak var wvWeb: WKWebView!// ham moi
override func viewDidLoad() {
super.viewDidLoad()
let url:URL = URL(string: "https://www.chess.com/")!
let req:URLRequest = URLRequest(url: url)
wvWeb.load(req)
UITableview //rotocon la delegate and datasoure
if let cell = tableView.dequeueReusableCell(withIdentifier: "CellTableViewCell", for: indexPath) as? CellTableViewCell {
cell.lblTitle.text = arrVietNam[indexPath.section][indexPath.row]
cell.imgPicture.image = UIImage(named: arrPicture[indexPath.section][indexPath.row])
}
return UITableViewCell()
// Step1:Layout for scrollview
let scroll:UIScrollView = UIScrollView()
view.addSubview(scroll)
scroll.translatesAutoresizingMaskIntoConstraints = false
scroll.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
scroll.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
scroll.widthAnchor.constraint(equalToConstant: 200)
scroll.heightAnchor.constraint(equalToConstant: 200)