Yes, there is an approach to align custom fonts to the center in SwiftUI. You can use the .baselineOffset modifier to adjust the vertical alignment of the custom font.
Here's an updated version of your code that centers the custom font:
`struct ContentView: View {
var body: some View {
VStack(spacing: 20){
Text("SEPTEMBER")
.font(.largeTitle)
.border(.blue)
Text("SEPTEMBER")
.font(Font.custom("Arial Hebrew", size: 20))
.baselineOffset(-0.25 * UIFont.preferredFont(forTextStyle: .body).lineHeight)
.border(.red)
}
}
}`
In this code, we're using the .baselineOffset modifier to move the baseline of the custom font down by a fraction of its line height. The specific value we're using (-0.25) is just a suggestion; you may need to adjust it to get the exact center alignment you want.
Note that we're also using UIFont.preferredFont(forTextStyle: .body).lineHeight to get the line height of the system font at the .body text style. This ensures that the offset will be proportional to the font size, and will work correctly on devices with different screen densities.
Post
Replies
Boosts
Views
Activity
The error "Cannot assign value of type 'hghg.SneakerStore' to type 'hghg.SneakerStore'" indicates that there is a type mismatch between the two instances of SneakerStore.
One possible reason for this error is that you have defined SneakerStore in multiple places in your project, which can result in two separate definitions of the same class with different types.
To resolve this error, make sure that the SneakerStore class is defined in only one place in your project, and that both instances of SneakerStore are using the same definition. You can also try cleaning your project by going to "Product" > "Clean Build Folder" in Xcode, and then rebuilding your project to see if that resolves the error.
If you're still having trouble, you can try providing more context or code snippets so that I can provide more specific guidance.
The error message "Module 'LUXforMac' not found" suggests that the Xcode build process is not generating a module map for the macOS target of your framework.
The module map is used to define the mapping between the Objective-C module name and the framework's headers. It's possible that the build script for your macOS target is not generating the module map file correctly or that it's not being included in the final product.
To fix this issue, you should check that the MODULEMAP_FILE build setting is properly set for the macOS target in your Xcode project. The value of this setting should point to the location of the module map file, relative to the project's source directory.
If the MODULEMAP_FILE build setting is correctly set and the module map is still not being generated, you can try to manually create the module map file for the macOS target. To do this, create a new file named "module.modulemap" in the same directory as your framework's headers. The contents of the file should be similar to the module map file used for the iOS target.
module LUXforMac {
header "LUX.h"
export *
}
Make sure that the HEADER_SEARCH_PATHS build setting is correctly set to include the directory that contains the module map file.
If you're still having trouble, you may need to provide more context or code snippets so that I can provide more specific guidance.