I cannot seem to add my custom font. I have dragged it into my project and added it as a target to my project.
Code creating a label as follows:
// Create Unlock Text
func createUnlockText() {
unlockText = SKLabelNode(fontNamed: "04b_19")
unlockText.name = "unlockText"
unlockText.text = "Goal: \(goalScore)"
unlockText.fontSize = 100
unlockText.fontColor = SKColor(red: 100.0, green: 100.0, blue: 255.0, alpha: 1.0)
unlockText.position = CGPoint(x: 0, y: (self.frame.size.height / 2.8))
unlockText.zPosition = 1
self.addChild(unlockText)
}
I have added the Fonts Provided by application in the plist so I cm confused :(
Here are the steps to add a custom font:
Drag and drop the text font into the project. (You have done it)
Add in info.plist (You have done it)
Check that the source is in the corresponding target. Select the font and in the right menu you have to list the targets, check it
out.
In the project, in the first folder, go to "Build Phases"> Copy Bundles and check that it is added, if not, add it.
Verify that the font name is correct.
To use it is done like this:
You can select it in the storyboard in the viewcontroller.
By code:
label.font = UIFont(name: "Montserrat-Light", size: 12.0)
Then in SpriteKit, are the same steps, but the code it's like this:
SKLabelNode(fontNamed: "Montserrat Light")
Related
When I change the label color on my display programmatically, but that doesn't really change the color of the label in my simulator
this is my code :
This code works for iOS v13.3, but not for iOS v12.4
lblClockOut.text = "text"
lblClockOut.textColor = UIColor(named: "Green-9920")
is there any other way?
before that I say thank you :)
Have you tried updating UI on main thread like,
DispatchQueue.main.async{ self.lblClockOut.textColor = UIColor(named: "Green-9920") }
In my projects I would apply colors like this:
extension UIColor {
static let green_9920 = #colorLiteral(red: 0.0862745098, green: 0.8509803922, blue: 0.4470588235, alpha: 1)
}
// Usage example:
lblClockOut.textColor = .green_9920
I've never had issues with simulators so maybe this will work for you. Your code seems fine at first glance so not sure why its not working but you could try resetting the iOS 12 simulator and maybe its something to do with the referencing of your custom color.
I am trying to set the button text for the following :
The first step I followed is to include the font file in the project. I then referred it in the Info.plist.
I copied the icon from the cheatsheet :
Then I set the font for the button in IB as follows :
As a result, I get a question mark on the button (both in IB and on running).
Just for cross checking, I set some other icon instead of this. It worked fine.
Where could the mistake be ?
You are using the wrong font. The one you want is FontAwesome5FreeSolid (fa-solid-900.ttf).
This works fine on my machine:
let s = "\u{f362} Convert"
let ss = NSAttributedString(string: s, attributes:
[.font : UIFont(name:"FontAwesome5FreeSolid", size:17)!])
let b = UIButton(type: .system)
b.frame = CGRect(x: 40, y: 40, width: 200, height: 200)
b.setAttributedTitle(ss, for: .normal)
self.view.addSubview(b)
Result:
In IB set only the font name and size , in code use something like this
self.backBu.setTitle(String(format:"%C",0xf053), for: .normal);
replace f053 with unicode that you want , also make sure that target memberShip is checked for the font resource and you add it to info.plist
I am trying to use the Nunito-ExtraBoldItalic font for my UILabel.
I followed the steps outlined in tutorials and other answers.
Add font to fonts folder. Made sure the target is set to the project.
Add the entry to plist.
Made sure the font is shown in build phase/copy bundle resources. It is shown.
I am using the following code to create a UIlabel:
uiLabel = UILabel(frame: CGRect(x: 0, y: 0, width: 160, height: 50))
let myfont = UIFont(name: "Nunito-ExtraBoldItalic", size: 14)
uiLabel!.font = myfont
uiLabel!.textColor = UIColor(red: CGFloat(51/255.0), green: CGFloat(33/255.0), blue: CGFloat(32/255.0), alpha: CGFloat(100.0))
addSubview(uiLabel!)
But UIFont returns nil.
Postscript name of font is "Nunito-ExtraBoldItalic".
I also tried running the following:
for familyName:String in UIFont.familyNames {
print("Family Name: \(familyName)")
for fontName:String in UIFont.fontNames(forFamilyName: familyName) {
print("--Font Name: \(fontName)")
}
}
My font is not shown.
The font is visible in storyboard and other areas.
I tried using the Nunito-ExtraBoldItalic, Nunito-ExtraBold Italic, Nunito-ExtraBold-Italic as names. None worked.
So I am not sure what the problem is.
Add the font file to the project.
Add "Fonts provided by application" in Info.plist.
<key>UIAppFonts</key>
<array>
<string>CarterOne.ttf</string>
</array>
Make sure the font file is listed in BuildPhase->Copy Bundle Resources.
Make sure the Target Membership is check.
Do a clean build cmd+option+shift+K
You also need to add the font to the .plist file
Please read the following:
https://developer.apple.com/documentation/uikit/text_display_and_fonts/adding_a_custom_font_to_your_app
Add the font name to this plist key:
"Fonts provided by application"
I'm trying to develop a keyboard and it should use a different font then the default one. Here's the line:
override func textDidChange(textInput: UITextInput?) {
textInput.font = UIFont(name: "font name", size: 30)
}
But it doesn't work.... How can I fix it?
Thanks.
Follow this steps to use custom Fonts
Drag and drop your font into Xcode
Choose options for adding these files:
Copy items if needed
Create groups
Add to targets:(your app name)
In your Info.plist file add a key named: Fonts provided by application, which is an array
Customize your font:
myUILabel.text = "demoText"
myUILabel.font = UIFont(name: "myCustomFont.ttf", size: 25)
I imported 2 *.ttf font files for a normal and bold font into xcode, set everything up in the .plist etc - and I can perfectly view the font in the storyboard now.
Unfortunately attributed textviews as well as labels or buttons will ignore my font when I set it in storyboard mode!
If I generate something programmatically it works fine, e.g. like this:
var testButton = UIButton()
testButton.setTitle("Abbrechen", forState: UIControlState.Normal)
testButton.backgroundColor = UIColor.blueColor()
testButton.titleLabel?.font = UIFont(name: "FaktConPro-Bold", size: 37)
testButton.tintColor = UIColor.redColor()
testButton.frame = CGRectMake(0 , 0, self.view.frame.width, 60)
view.addSubview(testButton)
any hints? does iOS prefer any format?
€dit:setting the labels and textfields to "plain" instead of "attributed" temporarily fixes the problem
This is a bug on Xcode. I already created a radar a couple of month ago. Here: http://openradar.appspot.com/radar?id=5117089870249984