TextView's font i not changing in storyboard - ios

as you can see in the above i'm trying to change my textView's font , but it didn't changing i searched some related terms on changing for like this one
and this , but nothing worked for me
i'm also not sure if this is the correct name of my desired font or not
titleTextView.font = UIFont(name: "Myriad-Condensed", size: 25)
even in this site they dont have anything related to my desired font which is Myriad pro Condensed according to storyboard's attribute inspector
anyone faced anything similar to this before ?? or any clue what i should do ? then please let me know

First you need a font to use. Download any of them in you cass its right here : http://ufonts.com/fonts/myriadpro-cond.html
After downloading drag & drop the font file (otf or ttf) into your project
Make sure you check the box next to your target or the font won’t actually get included in your app (even though it’ll probably show in Interface Builder).
Open up the Info.plist . Add a new array of strings to it: “Fonts provided by application”. Add the filenames for each font you want to use as String entries in the array. (That one ttf file you just added to your project )
Now you're good to go , select that font once again like you did in the attached image.
For more detail see this article https://grokswift.com/custom-fonts/

Related

Font works in storyboard but fails to work in iOS simuator (Xcode 8)

I've been working on the launch screen of an app and I ran across a problem. The custom font that I was using (grand hotel) shows up in the storyboard but is replaced by a default font in the simulator. It should be like this, but instead this happens. I've tried everything online: added it to the plist, set the target, put it in Copy Bundle Resources. I've looked everywhere but I can't seem to find a solution that solves my problem. Is there any way for me to fix this issue? Could it be because it is a launch screen?
Follow the below steps.
(1) Remove your custom fonts.
(2) Re-add your font like, Right click on your project --> add files --> select your custom font. (Make sure option copy items if needed is checked).
(3) Clean(⌘+shift+K) + Build(⌘+shift+B) your project.
To check if the custom fonts are availabel on runtime add this code:
print(UIFont.fontNames(forFamilyName: "Your_Custom_font_name")) // if it returns empty array it means fonts are not available on runtime and it is not added correctly.
Please check this... may any step you miss
http://codewithchris.com/common-mistakes-with-adding-custom-fonts-to-your-ios-app/
Did you somewhere set the font programmatically by name?
I figured out, that the name of a certain font is not necessarily the name, which is shown in Xcode. You can check out the real font names in Xcode by putting the following somewhere in your code:
for family: String in UIFont.familyNames {
print("\(family)")
for names: String in UIFont.fontNames(forFamilyName: family)
{
print("== \(names)")
}
}

Xcode 8 custom font doesn't show up in interface builder

I am trying to use custom font (Bebas Neue) in my iOS application. The steps I took are:
Copy the .otf files to the project.
Confirm the .otf files have set the project as target.
Added the .otf files in 'Fonts provided by application' in plist.
In Build Phases, the .otf files are in 'Copy Bundle Resources'.
Install the font on my Mac.
Try to print out all fonts available but I can't see my custom font.
The code I used:
for name in UIFont.familyNames() {
println(name)
if let nameString = name as? String
{
println(UIFont.fontNamesForFamilyName(nameString))
}
}
Trying to set the font in code and it worked.
The code I used:
textLabel?.font = UIFont(name: "BebasNeueRegular", size: 14)
But I can't set it in interface builder. Any idea?
Screenshots:
Try Below Steps: Code tested in Swift 3.
Step 1: Add Your custom font into your project( Make sure Add to Target
ticked).I am using "PermanentMarker.ttf","Pecita.otf" and "AROLY.ttf" font as a test font.
Note: Supporting font Type ttf and otf (Both font types should work)
Step 2: Modify the application-info.plist file.
Add the key "Fonts provided by application" in a new row and add "PermanentMarker.ttf" as new item in the Array "Fonts provided by application".
Your plist should looks like this
Now the font will be available in Interface Builder. To use the custom font in code we need to refer to it by name, but the name often isn’t the same as the font’s filename
Now, You can access the Custom Font from your viewController. I am testing the font by placing a UIlabel to the Storyboard like below.
Update 2: Working Solution
After, imported your custom font and updated your plist.selectlabel from your storyBoard,goto Attributes Inspectorunder Label>Text type> select to Attributed and choose your custom font from the list.
Output:
Update 1
If your custom font still not listed in Xcode font list.check the related link to your issue
http://codewithchris.com/common-mistakes-with-adding-custom-fonts-to-your-ios-app/
custom font not displaying on some simulator
Note: Still,You can assign BebasNeue or custom font programatically to your label or button etc. even its not showing in your interface Builder.If you having trouble setting font to your object programatically.try below method.
Assign font to UILabel:
label?.font = UIFont(name: "BebasNeue", size: 35) // Set to any size
Assign font to UIButton:
button.titleLabel?.font = UIFont(name: "BebasNeue", size: 35)
Assign font to UITextField:
textField.font = UIFont(name: "BebasNeue", size: 25)
Assign font to UINavigationBar:
navigationController?.navigationBar.titleTextAttributes = [NSFontAttributeName: UIFont(name: "BebasNeue", size: 25)!, NSForegroundColorAttributeName: UIColor.red]
Assign font to UIToolBar:
UIBarButtonItem.appearance().setTitleTextAttributes([NSFontAttributeName: UIFont(name: "BebasNeue", size: 25.0)!], for: UIControlState.normal)
Output:
Its Easy and simple now- Tested in Xcode 10 and swift 5
Steps to add font to your Xcode
Select your UILabel, UITextField or whatever then under fonts section and follow
Step 1
Select settings menu from left corner of font selection screen. And choose font manager option.
Step 2
Click on the add button as marked below.
Step 3
Select the folder that contains your font. It will be loaded into XCode fonts list.
Steps to add fonts to your project
Don't forget to add description to your plist with the key Fonts provided by application and put font files inside copy bundle resources under project target settings.
Yes! thats it.. njoy..
When using the same font (Bebas Neue), I experience the exact same problem: the font does not show up in the font list for Plain controls.
It does for Attributed controls, as described in Update 2 in Joes post, but then you're actually changing the attributedText instead of the regular text, which may lead to unwanted behavior. For example, you'll have to fiddle with NSMutableAttributedString to change the text or text color at runtime.
I did some investigation on this issue. I used FontLab Studio to modify the font and do some tests. I used Bebas Neue version 1.400 (dated September 15, 2014) from dafont.com.
Maybe the font file was somehow corrupted. Re-saved as .otf and .ttf: Didn't work.
Maybe the meta data of the font were corrupted. Copied all the glyphs to a new font and named that Bebas Neue: Didn't work.
I renamed the font from Bebas Neue to BN: It works! But why?
Maybe you can't use "Neue" in a font name (since Helvetica Neue was the iOS system font up to iOS 8). Renamed the font to Test Neue: Still works.
Maybe you can't use "Bebas" in a font name then? Renamed the font to Bebas: Still works.
What... Just to be sure, I changed the font name back to Bebas Neue: Doesn't work again.
I also tried BebasNeue: Also didn't work.
Then I changed the name to Bebas Neue Whatever: It works.
I really do not understand why this is happening.
Doesn't Apple or Xcode want you to use "Bebas Neue" or "BebasNeue" in the Interface Builder?
I had the normal Bebas Neue installed. Maybe the reference got corrupted?
I really can't tell. Maybe someone on a clean system can try if Bebas Neue works in their Xcode.
Anyway, I achieved my goal: being able to use Bebas Neue (I named the final version "Bebas Neue MyAppName") for Plain styled labels and buttons, so I can design my app as-is and don't have to fiddle around with attributed strings.
Finally, I found the root cause of issues with Bebas Neue fonts.
I don't remember where I have downloaded the fonts, but Bebas Neue fonts are inconsistent.
Download i.e. app called Typelight
Open not Regular, but i.e. Bold font with Typelight.
You need correct most of the Bebas Neue fonts.
maybe there is a difference between folder name and font name the solution would be:
Print all default fonts names.(without custom fonts)
Add custom fonts to project.
Print all fonts names.
and after that compare fonts names.
func printFontsNames() {
let fontFamilyNames = UIFont.familyNames
for familyName in fontFamilyNames {
print("------------------------------")
print("Font Family Name = [\(familyName)]")
let names = UIFont.fontNames(forFamilyName: familyName )
print("Font Names = [\(names)]")
}
}
You can actually just go into attributed fonts, click the custom font window. There click the gear in the upper left and click on the option manage fonts. A window should pop up and on the top and there should be a plus sign to allow you to add fonts. Just choose the custom font you downloaded like xyz.tff and then it should be added.
Important to note is that ttf file should be referenced in the p-list as well as in your project directory!
TLDR
Create a new user account in Mac OS and see if you are able to have success in the new account BEFORE going through all the steps that I went through below. In hindsight, I probably could have just performed steps 7 and 11 and saved hours of hassle.
Problem
After begrudgingly upgrading to Catalina from Mojave so that I could run the latest and not greatest version of Xcode (11.5), I was no longer able to select a custom font from the font picker for PLAIN text controls within interface builder.
As others have mentioned, attributed text works fine, because it uses the systems font picker instead of the "black box / where did these fonts come from???" picker that comes up when using plain text.
Failed Steps
I tried the following steps with no success:
Re-add the font files to the project in hopes that Xcode would fix
the link to the font table that the picker is loading from (still
have no idea why there are certain fonts in the picker and where it
is getting them from).
Reset the Mac OS font caches using several terminal commands in hopes that the picker is loading the list from a corrupt font cache in the OS
Reset the system fonts by choosing File > Restore Standard Fonts in the Font Book app
Screamed at the computer and cursed Apple for what they have become
Tried installing the fonts in the OS to see if that resolved anything, because I remembered it worked a couple years ago when I ran into something similar.
Searched the internet for any clues and tried virtually everything that seemed reasonable.
Created a brand new simple project ... still could not select a custom font ... ruh oh
Bring in the Big Guns
Cursed myself for not performing a CLEAN install of Catalina and decided to reinstall Catalina from scratch.
Realized that I made a mistake using Time Machine to backup my data before re-installing, because it would not let me bring in just my data files. The Migration Assistant requires the Library data to be imported (option was grayed out when restoring), which I did not want to do ... cursed Apple and myself again because I knew this was gonna bite me in the ... as I suspected there was garbage in the profile that was causing this (I was right ... see below)
Tried to select the font in Xcode while running under the IMPORTED account from Migration Assistant ... SAME PROBLEM ... could not select a custom font
SUCCESS!!!
Created a new user and created a new simple project under that account. BINGO!!! I could select a font now!!! Somehow my user account was corrupted during the upgrade to Catalina
It was an old bug since Xcode 3.x:
there is a bug/known issue with IB on XCode 3.x with non-standard fonts and Interface Builder. Custom fonts generally need to be set programatically (via [UIFont fontWithName:])
There are some work around like this with User Defined Runtime Attribute and categories .
I had similar problem
added custom font and also assign it to UILabel all working fine but after a few times later it's wont work as expected.
Trying all solution but nothing work for me. So here is my solution, again going to previous UILabel (already have newly added custom font) select->label->select newly added font. Check other UI controls Font.
now it's working fine.
Hope this help newDevs...
This is still a recurring issue for me with Swift 4.2, even without making any changes that would cause it.
Removing the font files from the Xcode project and adding them again fixes the problem (until next time).
In my case, a font family was missing in Interface builder, because one of the fonts from that family was not added to the project, but was indicated in the info.plist file.
Generally removing all my custom fonts from the project and adding them again - fixed the issue.

Can't change font in XCode 6.1.1

Within XCode 6.1.1 I'm unable to change the font on my label within my storyboard. I can set 'Text' to either 'Plain' or 'Attributed', but then [T] next to Helevetica Neue 17.0 appears grayed out, and it does not do anything when I click it. This happens in all of my projects.
Screenshot here: https://i.imgur.com/3VOSsVn.png
Thank you!
Edit: Unfortunately none of the answers below have answered my question yet. The [T] is unclickable.. it is grayed out so I can't change the Font to custom under there. And while I could go in and enter code to change the font, I would prefer to do it through the GUI.
This problem was driving me crazy - your workaround works for the normal storyboard, but not for the Watch storyboard which has a custom fonts popup.
I finally found this page:
https://github.com/synergy/synergy/issues/4109
It's a bug with using Synergy - I connected a USB mouse to my Mac and when I click the font "T" icon with the USB mouse, it works!!!!
Actually, you have to first select a syntax category in the detail area. You can press CMD+A to select all categories. Then you can click the "T" and select a new font.
See here: https://developer.apple.com/library/ios/recipes/xcode_help-fonts_and_colors_preferences_help/Recipe.html
In the "font", change "system" to "custom”
You can set font for labels in two ways- programmatically and in storyboard.
In your storyboard, you need to click the little T and then select the wanted font.
In your code, assuming you already set the appropriate IBOutlets, you can use something like
[self.theTextLabel setFont:[UIFont boldSystemFontOfSize:17.0]];
Tap on the "T" sign next to the already assigned font, then change "system" to "custom”. Once the settings are on custom the font can be changed as well as it's weight (ie. light, bold...)
I did find a workaround... I can bring up the font menu by crtl-shift-opt-T and change the font there and changes I make are reflected on the page... but the [T] is still still grayed out for some reason.

Custom Font Issue in iOS

In my app, I used custom fonts. It works fine for UILabels, etc...
But the Title is cut from top for Button.
"See the S"
What is happening and how can I resolve this??
try setting button.contentEdgeInsets property to align the title within the button, if it is an issue of misligned baseline of the font you can do this
button.titleLabel.baselineAdjustment = UIBaselineAdjustmentAlignCenters
a few steps:
Include your fonts in your XCode project
Make sure that they’re included in the target
Double check that your fonts are included as Resources in your bundle
Include your iOS custom fonts in your application plist
Find the name of the font
Use UIFont and specify the name of the font
detail for this:
http://codewithchris.com/common-mistakes-with-adding-custom-fonts-to-your-ios-app/
thanks!
In my case it was the font file that was corrupted.
Try to open the ttf file in your mac, select the 'S' and see if the frame that appears cuts off the letter.
My solution was to change the ttf file.

iOS : Roboto Condensed through Interface builder

I have a weird issue here... An app uses some custom font (Roboto Condensed for instance).
I added my font to my project. They are associated with the target. They are declared in the info.plist and the typo is right (copy/paste from the original files) and they contain the extension of course. They are in the "Copy ressources" of the build phase, they are part of the Font Family when I log them but enumerating fonts, they work through IB, and they are not set when the app is running... The fonts were download from the latest version on the Google website.
Weirdest thing : I have other custom font, and they are working.
Even weirder : if I set the font programmatically, it works...
It seems that it is related to IB (font name, family?)
I'm running out of options here. Have you encountered this kind of behavior?
Thanks.
I did not find any solution. The only workaround is to have outlets for every font specific view and set it into code :-/

Resources