Skip to content

Instantly share code, notes, and snippets.

Avatar

Toshihiko Arai araemon

View GitHub Profile
View ViewController.swift
class ViewController: UIViewController {
@IBOutlet weak var bottomLayoutConstraint: NSLayoutConstraint!
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow), name: UIResponder.keyboardWillChangeFrameNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name: UIResponder.keyboardWillHideNotification, object: nil)
}
View extension.swift
extension UIView {
var csSafeAreaInsets: UIEdgeInsets {
if #available(iOS 11.0, *) {
return self.safeAreaInsets
} else {
return .zero
}
}
}
View className.swift
extension UIViewController {
var className: String {
return String(describing: type(of: self))
}
}
class hoge {
func doSomething(rootViewController:UIViewController)
let className = rootViewController.className
View orientationDidChange.swift
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(orientationDidChange(_:)), name: UIDevice.orientationDidChangeNotification, object: nil)
}
var lastOrientation: UIDeviceOrientation?
@objc func orientationDidChange(_ notification: NSNotification) {
let device = UIDevice.current
if device.orientation.isLandscape {
View controllViews.swift
for v in view.subviews {
if v.isKind(of: UISegmentedControl.self) {
let sc = v as! UISegmentedControl
if #available(iOS 13.0, *) {
sc.selectedSegmentTintColor = .pink
} else {
// Fallback on earlier versions
}
sc.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.white], for: .normal)
sc.backgroundColor = .black
View buttonTint.swift
let image = UIImage(named: "hoge")?.withRenderingMode(UIImage.RenderingMode.alwaysTemplate)
button.setImage(image, for: .normal)
button.tintColor = .red
View barStyle.swift
// ナビゲーションバーのタイトル
self.navigationItem.title = "ランキング"
// ナビゲーションバーのタイトル色
self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
// ナビゲーションバーの背景色
self.navigationController?.navigationBar.barTintColor = .questionAreaBackground
let closeItem = UIBarButtonItem(title: "x", style: .plain, target: self, action: #selector(closeWindow))
View cellBackground.swift
override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
cell.backgroundColor = .black
}
View originalColor.swift
extension UIColor {
static var myColor = UIColor(red: 152.0 / 255.0, green: 99.0 / 255.0, blue: 99.0 / 255.0, alpha: 1.0)
}
View hash.swift
import Foundation
import CommonCrypto
enum CryptoAlgorithm {
case MD5, SHA1, SHA224, SHA256, SHA384, SHA512
var digestLength: Int {
var result: Int32 = 0
switch self {
case .MD5: result = CC_MD5_DIGEST_LENGTH
You can’t perform that action at this time.