Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
Material
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dmitriy Stepanets
Material
Commits
f714cc3a
Commit
f714cc3a
authored
Apr 06, 2016
by
Ramon Vicente
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix load of custom font behind a custom bundle
parent
450ccf24
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
4 deletions
+53
-4
Sources/iOS/MaterialFont.swift
+44
-0
Sources/iOS/RobotoFont.swift
+9
-4
No files found.
Sources/iOS/MaterialFont.swift
View file @
f714cc3a
...
...
@@ -58,4 +58,47 @@ public struct MaterialFont : MaterialFontType {
public
static
func
italicSystemFontWithSize
(
size
:
CGFloat
)
->
UIFont
{
return
UIFont
.
italicSystemFontOfSize
(
size
)
}
public
static
func
loadFontIfNeeded
(
fontName
:
String
)
{
FontLoader
.
loadFontIfNeeded
(
fontName
)
}
}
private
class
FontLoader
{
static
var
loadedFonts
:[
String
:
String
]
=
[:]
static
func
loadFontIfNeeded
(
fontName
:
String
)
{
let
loadedFont
=
FontLoader
.
loadedFonts
[
fontName
]
if
(
loadedFont
==
nil
&&
UIFont
(
name
:
fontName
,
size
:
1
)
==
nil
)
{
FontLoader
.
loadedFonts
[
fontName
]
=
fontName
let
bundle
=
NSBundle
(
forClass
:
FontLoader
.
self
)
var
fontURL
:
NSURL
?
=
nil
let
identifier
=
bundle
.
bundleIdentifier
if
identifier
?
.
hasPrefix
(
"org.cocoapods"
)
==
true
{
fontURL
=
bundle
.
URLForResource
(
fontName
,
withExtension
:
"ttf"
,
subdirectory
:
"io.cosmicmind.material.fonts.bundle"
)
}
else
{
fontURL
=
bundle
.
URLForResource
(
fontName
,
withExtension
:
"ttf"
)
}
if
fontURL
!=
nil
{
let
data
=
NSData
(
contentsOfURL
:
fontURL
!
)
!
let
provider
=
CGDataProviderCreateWithCFData
(
data
)
let
font
=
CGFontCreateWithDataProvider
(
provider
)
!
var
error
:
Unmanaged
<
CFError
>
?
if
!
CTFontManagerRegisterGraphicsFont
(
font
,
&
error
)
{
let
errorDescription
:
CFStringRef
=
CFErrorCopyDescription
(
error
!.
takeUnretainedValue
())
let
nsError
=
error
!.
takeUnretainedValue
()
as
AnyObject
as!
NSError
NSException
(
name
:
NSInternalInconsistencyException
,
reason
:
errorDescription
as
String
,
userInfo
:
[
NSUnderlyingErrorKey
:
nsError
])
.
raise
()
}
}
}
}
}
\ No newline at end of file
Sources/iOS/RobotoFont.swift
View file @
f714cc3a
...
...
@@ -48,7 +48,8 @@ public struct RobotoFont : MaterialFontType {
/**
:name: thinWithSize
*/
public
static
func
thinWithSize
(
size
:
CGFloat
)
->
UIFont
{
public
static
func
thinWithSize
(
size
:
CGFloat
)
->
UIFont
{
MaterialFont
.
loadFontIfNeeded
(
"Roboto-Thin"
)
if
let
f
=
UIFont
(
name
:
"Roboto-Thin"
,
size
:
size
)
{
return
f
}
...
...
@@ -65,7 +66,8 @@ public struct RobotoFont : MaterialFontType {
/**
:name: lightWithSize
*/
public
static
func
lightWithSize
(
size
:
CGFloat
)
->
UIFont
{
public
static
func
lightWithSize
(
size
:
CGFloat
)
->
UIFont
{
MaterialFont
.
loadFontIfNeeded
(
"Roboto-Light"
)
if
let
f
=
UIFont
(
name
:
"Roboto-Light"
,
size
:
size
)
{
return
f
}
...
...
@@ -82,7 +84,8 @@ public struct RobotoFont : MaterialFontType {
/**
:name: regularWithSize
*/
public
static
func
regularWithSize
(
size
:
CGFloat
)
->
UIFont
{
public
static
func
regularWithSize
(
size
:
CGFloat
)
->
UIFont
{
MaterialFont
.
loadFontIfNeeded
(
"Roboto-Regular"
)
if
let
f
=
UIFont
(
name
:
"Roboto-Regular"
,
size
:
size
)
{
return
f
}
...
...
@@ -92,7 +95,8 @@ public struct RobotoFont : MaterialFontType {
/**
:name: mediumWithSize
*/
public
static
func
mediumWithSize
(
size
:
CGFloat
)
->
UIFont
{
public
static
func
mediumWithSize
(
size
:
CGFloat
)
->
UIFont
{
MaterialFont
.
loadFontIfNeeded
(
"Roboto-Medium"
)
if
let
f
=
UIFont
(
name
:
"Roboto-Medium"
,
size
:
size
)
{
return
f
}
...
...
@@ -117,6 +121,7 @@ public struct RobotoFont : MaterialFontType {
:name: boldWithSize
*/
public
static
func
boldWithSize
(
size
:
CGFloat
)
->
UIFont
{
MaterialFont
.
loadFontIfNeeded
(
"Roboto-Bold"
)
if
let
f
=
UIFont
(
name
:
"Roboto-Bold"
,
size
:
size
)
{
return
f
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment