Last active
October 7, 2024 19:00
-
-
Save eldaroid/7d88be42781e6d0106986c9055004454 to your computer and use it in GitHub Desktop.
RU: Инструмент для отладки UI в SwiftUI, позволяя более детально контролировать и понимать процесс вычисления размеров и размещения представлений. EN: A tool for debugging UIs in SwiftUI, allowing for more detailed control and understanding of the process of calculating view sizing and placement
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
struct LogSizes: Layout { | |
var label: String | |
func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) -> CGSize { | |
assert(subviews.count == 1) | |
print(String(format: "предлагают _%@_: →%.2f x ↓%.2f", label, proposal.width ?? 0, proposal.height ?? 0)) | |
let result = subviews[0].sizeThatFits(proposal) | |
print(String(format: "ответ от _%@_: →%.2f x ↓%.2f", label, result.width, result.height)) | |
return result | |
} | |
func placeSubviews(in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) { | |
subviews[0].place(at: bounds.origin, proposal: proposal) | |
} | |
} | |
extension View { | |
func logSizes(_ label: String) -> some View { | |
LogSizes(label: label) { self } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Пример использования:
Ответ:
P.S.: моя картинка размеров 393.00 x 759.00