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
extension UIView { | |
static let swizzle: Void = { | |
let originalSelector = #selector(layoutSubviews) | |
let swizzledSelector = #selector(swizzled_layoutSubviews) | |
guard let originalMethod = class_getInstanceMethod(UIView.self, originalSelector) else { return } | |
guard let swizzledMethod = class_getInstanceMethod(UIView.self, swizzledSelector) else { return } | |
method_exchangeImplementations(originalMethod, swizzledMethod) | |
}() |
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
@objc func veryUsefulMethod() { | |
guard let superclass = superclass else { return } | |
let objcSelector = Selector("veryUsefulMethod") | |
typealias CFunction = @convention(c) (AnyObject, Selector) -> Void | |
let impl = class_getMethodImplementation(superclass, objcSelector) | |
let callableImpl = unsafeBitCast(impl, to: CFunction.self) | |
callableImpl(self, objcSelector) |
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
let objcSelector = Selector("veryUsefulMethod") | |
typealias CFunction = @convention(c) (AnyObject, Selector) -> Void | |
let impl = class_getMethodImplementation(type(of: self).self, objcSelector) | |
let callableImpl = unsafeBitCast(impl, to: CFunction.self) | |
callableImpl(self, objcSelector) |
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
@objc func _needsDoubleUpdateConstraintsPass() -> Bool { | |
return true | |
} | |
override var intrinsicContentSize: CGSize { | |
return attributedText?.size(forWidth: (engineBounds ?? bounds).width) ?? .zero | |
} | |
var engineBounds: CGRect? { | |
let objcSelector = "_nsis_compatibleBoundsInEngine:") |
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
[<CustomLabel 0x7fcb8350d0d0>/UILabel _prepareForFirstIntrinsicContentSizeCalculation] | |
... | |
[<CustomLabel 0x7fcb8350d0d0>/UILabel _needsDoubleUpdateConstraintsPass] -> 1 | |
... | |
[<CustomLabel 0x7fcb8350d0d0>/UILabel _prepareForSecondIntrinsicContentSizeCalculationWithLayoutEngineBounds:{{20, 20}, {25000000, 20.5}}] |
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
@objc func _prepareForSecondIntrinsicContentSizeCalculation(withLayoutEngineBounds bounds: CGRect) { | |
print(bounds) | |
} |
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
override var intrinsicContentSize: CGSize { | |
return attributedText?.size(forWidth: (fittingSize ?? bounds).width) ?? .zero | |
} | |
var fittingSize: CGRect? |
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
override func systemLayoutSizeFitting( | |
_ targetSize: CGSize, | |
withHorizontalFittingPriority horizontalFittingPriority: UILayoutPriority, | |
verticalFittingPriority: UILayoutPriority) -> CGSize | |
{ | |
// Прокинуть верный размер с учетом отступов | |
(content as? ASLabel)?.fittingSize = computeContentTargetSize(for: targetSize) | |
return super.systemLayoutSizeFitting(...) | |
} |
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
extension NSAttributedString { | |
func size(forWidth width: CGFloat) -> CGSize { | |
return boundingRect( | |
with: CGSize(width: width, height: CGFloat.greatestFiniteMagnitude), | |
options: [.usesLineFragmentOrigin, .usesFontLeading], | |
context: nil | |
).size | |
} | |
} |