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
/* | |
Change UIAlert message textColor | |
*/ | |
extension UIAlertAction { | |
var titleTextColor: UIColor? { | |
get { | |
return self.value(forKey: "titleTextColor") as? UIColor | |
} set { |
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
// return UIImage.Orientation | |
private func imageOrientation(deviceOrientation: UIDeviceOrientation = UIDevice.current.orientation, | |
cameraPosition: AVCaptureDevice.Position = .front) -> UIImage.Orientation { | |
var deviceOrientation = deviceOrientation | |
if deviceOrientation == .faceDown || deviceOrientation == .faceUp || deviceOrientation == .unknown { | |
deviceOrientation = currectDeviceOrientation() | |
} |
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
// return UIImage.Orientation | |
private func imageOrientation(deviceOrientation: UIDeviceOrientation = UIDevice.current.orientation, | |
cameraPosition: AVCaptureDevice.Position = .front) -> UIImage.Orientation { | |
var deviceOrientation = deviceOrientation | |
if deviceOrientation == .faceDown || deviceOrientation == .faceUp || deviceOrientation == .unknown { | |
deviceOrientation = currectDeviceOrientation() | |
} |
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
/* | |
關閉UIView Anitmate小技巧。 | |
有時候設定一系列 View 互動動畫, 突然遇到一個需求,需要關閉特定動畫,但是其他動畫要繼續執行的需求時, | |
就會特別頭痛。 | |
比如內建 TableView delete/ insert 動畫 + 自定義的其他動畫時,處理起來會特別煩瑣。 | |
而我們可以用簡單的 UIView.performWithoutAnimation 配上 main Therad 處理這件事情 | |
*/ | |
UIView.performWithoutAnimation { | |
// 動畫被取消,但是自動判斷Difference 不會失效 |
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
/* | |
上一篇取消動畫使用的是 UIView.performWithoutAnimation {} | |
很好用,但是還是有遺漏的部分,如果原第三方套件把動畫包在 DispathQueue.main 中 | |
動畫就會正常運作。 | |
這一篇介紹的方法將會強制取所任何動畫,概念上就是直接在View底層禁止安裝動畫。 | |
主件~ | |
開關: UIView.setAnimationsEnabled(Bool) | |
搭配~ | |
CATransaction.begin() |
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
/* | |
UIKit constraint 設定雖然簡單,但是非常繁瑣, | |
往往一個View 自少就要設定 4 條 constraint , | |
數量一堆也很花時間。 | |
透過 extension UIVIew 將最常用的代碼打包, | |
可以簡化Constraint,加快刻畫UI的時間 | |
*/ | |
extension UIView { |
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
import UIKit | |
public struct AnchoredConstraints { | |
public var top, leading, bottom, trailing, width, height: NSLayoutConstraint? | |
} | |
extension UIView { | |
@discardableResult | |
func anchor(top: NSLayoutYAxisAnchor?, leading: NSLayoutXAxisAnchor?, bottom: NSLayoutYAxisAnchor?, trailing: NSLayoutXAxisAnchor?, padding: UIEdgeInsets = .zero, size: CGSize = .zero) -> AnchoredConstraints { |
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 | |
// Practice_TapToOpenZoomInNextBackgroundView | |
// | |
// Created by Woody on 2020/12/14. | |
// | |
import UIKit |
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
/* | |
UIImage 染色 | |
String 塞圖片 | |
*/ | |
import UIKit | |
extension UIImage { | |
func tinted(color: UIColor) -> UIImage? { | |
let image = withRenderingMode(.alwaysTemplate) |