objective c - Custom fonts in iOS 8 not showing -



objective c - Custom fonts in iOS 8 not showing -

when building ios 7, custom fonts displayed in uilabel correctly. building xcode 6 , ios 8 "standard" font displayed.

code:

uilabel *label = [[uilabel alloc] initwithframe:rect]; uifont *font = [[captheme sharedtheme] apptitlefont]; label.text = title; label.textalignment = nstextalignmentcenter; label.textcolor = [uicolor whitecolor]; label.backgroundcolor = [uicolor clearcolor]; label.alpha = klabelalphaconstant; [label setfont:font];

...

- (uifont *)apptitlefont { nsarray *familynames = [uifont familynames]; (nsstring *afamilyname in familynames) { nsarray *fontnames = [uifont fontnamesforfamilyname:afamilyname]; nslog(@"familyname: %@", afamilyname); (nsstring *afontname in fontnames) { nslog(@" %@", afontname); } } homecoming [uifont fontwithfamily:@"myfont" size:15.0f]; }

...

+ (uifont*)fontwithfamily:(nsstring*)fontfamily size:(float)size { if (floor(nsfoundationversionnumber) <= nsfoundationversionnumber_ios_6_1) { homecoming [uifont fontwithname:fontfamily size:size]; } else { uifont *font = [uifont fontwithname:fontfamily size:size]; uifontdescriptor *des = [[font fontdescriptor] fontdescriptorbyaddingattributes:@{ uifontdescriptortextstyleattribute: uifonttextstyleheadline, uifontdescriptorsizeattribute: @(size) }]; uifont *finalfont = [uifont fontwithdescriptor:des size:0.0]; homecoming finalfont; } }

let's phone call font "myfont". displayed in debug prints as:

familyname: myfont myfont myfont-bold

i have tried both add together ttf , otf file. added under fonts provided application in plist file. added target. have tried using 1 of fonts.

interesting have code adjust size of label based on labels size. when entering font family name not exists (i.e. "myfont123") create text not show @ all, meaning recognizes custom font exists, wont show it.

any ideas?

here demo project created show problem: https://www.dropbox.com/s/mkn7xb3fb2lmh20/customlabel.zip?dl=0 run using ios 8 , font not shown.

edit: guess cannot utilize fontdescriptors custom fonts i'm original problem, crash on ios 8 error:

*** terminating app due uncaught exception 'nsinternalinconsistencyexception', reason: 'scaledvalueforvalue: called on font doesn't have text style set'

similar 1 scaledvalueforvalue: called on font doesn't have text style set

have added files info.plist file yet?

i'd recommend reading article well.

http://codewithchris.com/common-mistakes-with-adding-custom-fonts-to-your-ios-app/

ios objective-c fonts ios8

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -