Skip to content

Instantly share code, notes, and snippets.

View ikju's full-sized avatar
๐Ÿ 
Working from home

Ik Ju Song ikju

๐Ÿ 
Working from home
View GitHub Profile
let a = 1
let str = "hello"
print("์ž๋ฃŒํ˜• : ",type(of:a))
print("์ž๋ฃŒํ˜• : ",type(of:str))
//๊ฒฐ๊ณผ
//์ž๋ฃŒํ˜• Int
//์ž๋ฃŒํ˜• String
let str : String = "์ธ๊ธฐ์ˆœ"
print("๋ณ€ํ™˜ : ", str.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed))
//๊ฒฐ๊ณผ
๋ณ€ํ™˜ : %EC%9D%B8%EA%B8%B0%EC%88%9C
์‚ฌ์šฉ์˜ˆ์‹œ get์˜ value ๊ฐ’์ด db์—์„œ ํ•œ๊ธ€๊ณผ ์ผ์น˜ํ•˜๋‹ค๋ฉด
https:/localhost.com?keyword=%EC%9D%B8%EA%B8%B0%EC%88%9 // %EC%9D%B8%EA%B8%B0%EC%88%9 <- ์ธ๊ธฐ์ˆœ
button.translatesAutoresizingMaskIntoConstraints = false
button.setTitle("๋”๋ณด๊ธฐ", for: .normal) //title๋„ฃ๊ธฐ
button.setImage(#imageLiteral(resourceName: "arrow_left_48px"), for: .normal)// ์ด๋ฏธ์ง€ ๋„ฃ๊ธฐ
button.setTitleColor(.black, for: .normal)
button.imageView?.contentMode = .scaleAspectFit
button.titleLabel?.font = .boldSystemFont(ofSize: 12)
button.contentHorizontalAlignment = .center
button.semanticContentAttribute = .forceRightToLeft //<- ์ค‘์š”
Usage:
var color1 = hexStringToUIColor("#d3d3d3")
Swift 5: (Swift 4+)
func hexStringToUIColor (hex:String) -> UIColor {
var cString:String = hex.trimmingCharacters(in: .whitespacesAndNewlines).uppercased()
if (cString.hasPrefix("#")) {
cString.remove(at: cString.startIndex)
let search_textField : UITextField =
{
let textfield = UITextField()
textfield.translatesAutoresizingMaskIntoConstraints = false
textfield.placeholder = "๋‚ด์šฉ์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."
//ํ…Œ๋‘๋ฆฌ์„  ์ž‘์—…
textfield.layer.cornerRadius = 2
textfield.layer.borderWidth = 2
textfield.layer.borderColor = UIColor.gray.cgColor.copy(alpha: 0.8)
let alert = UIAlertController(title: "์•Œ๋ฆผ", message: "๋ ๋ฆฌ๋ง~~~~", preferredStyle: UIAlertController.Style.alert)
let okAction = UIAlertAction(title: "OK", style: .default) { (action) in
//OK ๋ฒ„ํŠผ ๋ˆ„๋ฅธ๋’ค ์ˆ˜ํ–‰ํ•  ์ฝ”๋“œ
}
alert.addAction(okAction)
let alert = UIAlertController(title: "์•Œ๋ฆผ", message: "๋ ๋ฆฌ๋ง~~~~", preferredStyle: UIAlertController.Style.alert)
let okAction = UIAlertAction(title: "OK", style: .default) { (action) in
//OK ๋ฒ„ํŠผ ๋ˆ„๋ฅธ๋’ค ์ˆ˜ํ–‰ํ•  ์ฝ”๋“œ
}
alert.addAction(okAction)
func validpassword(mypassword : String) -> Bool
{//์ˆซ์ž+๋ฌธ์ž ํฌํ•จํ•ด์„œ 8~20๊ธ€์ž ์‚ฌ์ด์˜ text ์ฒดํฌํ•˜๋Š” ์ •๊ทœํ‘œํ˜„์‹
let passwordreg = ("(?=.*[A-Za-z])(?=.*[0-9]).{8,20}")
let passwordtesting = NSPredicate(format: "SELF MATCHES %@", passwordreg)
return passwordtesting.evaluate(with: mypassword)
}
let textField = UITextField()
textField.textContentType = .newPassword
textField.isSecureTextEntry = true
์œ„์™€๊ฐ™์ด ์ž…๋ ฅํ•˜๋ฉด ์ผ๋ฐ˜์ ์œผ๋กœ ์•ฑ ์‚ฌ์šฉํ• ๋•Œ ํŒจ์Šค์›Œ๋“œ ์ž…๋ ฅํ•˜๋“ฏ์ด
๊ธ€์ž๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ๋™๊ทธ๋ผ๋ฏธ๋กœ ํ‘œํ˜„๋ฉ๋‹ˆ๋‹ค.
mport UIKit
//๋ฐ์ดํ„ฐ ์ „์†ก์„ ์œ„ํ•ด ํ”„๋กœํ† ์ฝœ์„ ์„ ์–ธํ•œ๋‹ค.
protocol PassData
{
func passdata(data : String)
}
// 1. B-&gt;A๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ์ „์†กํ•˜๊ธฐ ์œ„ํ•ด์„œ ํ”„๋กœํ† ์ฝœ์„ ์„ ์–ธํ•˜๊ณ  ๊ทธ์•ˆ์— ๋ฉ”์„œ๋“œ๋ฅผ ๋งŒ๋“ ๋‹ค.
class page2: UIViewController {