Post

Replies

Boosts

Views

Created

SwiftUI size to fit Font using GeometryReader, font is too big
I am using GeometryReader to calculate the size of font to use to fit several lines of text, however it is always too big. What can be wrong with my calculation? Here's a simply Playground import SwiftUI import PlaygroundSupport struct MainView : View { var body: some View { VStack { SomeView() .frame(width: 508.0, height: 246.5) } } } struct SomeView: View { let newData = ["1", "2", "3", "4", "5", "6", "7", "8"] var lines: Int { newData.count } var body: some View { GeometryReader { geometry in VStack(alignment: .leading, spacing: 0) { ForEach(0..<lines) { idx in Text(newData[idx]) .padding(0) } } .font(.system(size: geometry.size.height / CGFloat(lines))) .onAppear { print(geometry.size) print(lines) print(geometry.size.height / CGFloat(lines)) } } } } PlaygroundPage.current.setLiveView(MainView()) This gives me this result which I need to show all 8 lines:  The GeometryReader correctly reports the height of the box to be 246.5 and the number of lines to be 8 which results in a 30.8125 font size. It seems the font size needs some additional padding but how do I calculate this? I want to be able to supply an unknown amount of data and have it fill the box. (Well I am actually using a LazyVGrid which is suffering the same issue).
0
0
2.1k
Sep ’21
My Widget Extension will not build with Bitcode
I have just updated my iMac to an M1 and now one of my projects is giving me these warnings for 3 of the libraries embedded in a Widget Extension: ld: warning: all bitcode will be dropped because '/Users/..../DJSwiftHelpers_Extension' was built without bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target. I understand that the app needs all libraries to be built with bitcode in order to be bitcode compatible. 2 of the libraries are my own, one in fact is actually built inside the same project and all have bitcode enabled. The libraries have 2 versions, 1 with "Allow app extension safe API only" and the other without. It's only the app extension libraries that are an issue. Those embedded in a Watch extension are fine. Those embedded in Intents are fine. It's just the Widget extension that complains so I don't think the issue is the Frameworks. I can clear the warnings by disabling bitcode for the Widget Extension, however on uploading the app to the App Store, bitcode is in fact disabled for the whole app. So I guess my questions are: Why has this only become an issue on an M1 mac and not on my Intel Mac? Can widget extensions support bitcode? Or is the bitcode setting just ignored? Is it really impossible to use bitcode when providing a Widget Extension?
3
0
3.6k
Sep ’21
SwiftUI size to fit Font using GeometryReader, font is too big
I am using GeometryReader to calculate the size of font to use to fit several lines of text, however it is always too big. What can be wrong with my calculation? Here's a simply Playground import SwiftUI import PlaygroundSupport struct MainView : View { var body: some View { VStack { SomeView() .frame(width: 508.0, height: 246.5) } } } struct SomeView: View { let newData = ["1", "2", "3", "4", "5", "6", "7", "8"] var lines: Int { newData.count } var body: some View { GeometryReader { geometry in VStack(alignment: .leading, spacing: 0) { ForEach(0..<lines) { idx in Text(newData[idx]) .padding(0) } } .font(.system(size: geometry.size.height / CGFloat(lines))) .onAppear { print(geometry.size) print(lines) print(geometry.size.height / CGFloat(lines)) } } } } PlaygroundPage.current.setLiveView(MainView()) This gives me this result which I need to show all 8 lines:  The GeometryReader correctly reports the height of the box to be 246.5 and the number of lines to be 8 which results in a 30.8125 font size. It seems the font size needs some additional padding but how do I calculate this? I want to be able to supply an unknown amount of data and have it fill the box. (Well I am actually using a LazyVGrid which is suffering the same issue).
Replies
0
Boosts
0
Views
2.1k
Activity
Sep ’21
My Widget Extension will not build with Bitcode
I have just updated my iMac to an M1 and now one of my projects is giving me these warnings for 3 of the libraries embedded in a Widget Extension: ld: warning: all bitcode will be dropped because '/Users/..../DJSwiftHelpers_Extension' was built without bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target. I understand that the app needs all libraries to be built with bitcode in order to be bitcode compatible. 2 of the libraries are my own, one in fact is actually built inside the same project and all have bitcode enabled. The libraries have 2 versions, 1 with "Allow app extension safe API only" and the other without. It's only the app extension libraries that are an issue. Those embedded in a Watch extension are fine. Those embedded in Intents are fine. It's just the Widget extension that complains so I don't think the issue is the Frameworks. I can clear the warnings by disabling bitcode for the Widget Extension, however on uploading the app to the App Store, bitcode is in fact disabled for the whole app. So I guess my questions are: Why has this only become an issue on an M1 mac and not on my Intel Mac? Can widget extensions support bitcode? Or is the bitcode setting just ignored? Is it really impossible to use bitcode when providing a Widget Extension?
Replies
3
Boosts
0
Views
3.6k
Activity
Sep ’21