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
23c46664
Commit
23c46664
authored
Jul 13, 2016
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
renamed MaterialFont to Font and updated Font for Swift 2.3
parent
dd004d08
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
105 additions
and
70 deletions
+105
-70
Material.xcodeproj/project.pbxproj
+6
-6
Sources/iOS/Font.swift
+41
-26
Sources/iOS/RobotoFont.swift
+58
-38
No files found.
Material.xcodeproj/project.pbxproj
View file @
23c46664
...
...
@@ -53,7 +53,7 @@
96BCB7C11CB40DC500C806FE
/* MaterialDepth.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96BCB7781CB40DC500C806FE
/* MaterialDepth.swift */
;
};
96BCB7C21CB40DC500C806FE
/* MaterialDevice.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96BCB7791CB40DC500C806FE
/* MaterialDevice.swift */
;
};
96BCB7C31CB40DC500C806FE
/* MaterialEdgeInset.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96BCB77A1CB40DC500C806FE
/* MaterialEdgeInset.swift */
;
};
96BCB7C41CB40DC500C806FE
/*
MaterialFont.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96BCB77B1CB40DC500C806FE
/* Material
Font.swift */
;
};
96BCB7C41CB40DC500C806FE
/*
Font.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96BCB77B1CB40DC500C806FE
/*
Font.swift */
;
};
96BCB7C51CB40DC500C806FE
/* MaterialGravity.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96BCB77C1CB40DC500C806FE
/* MaterialGravity.swift */
;
};
96BCB7C61CB40DC500C806FE
/* Icon.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96BCB77D1CB40DC500C806FE
/* Icon.swift */
;
};
96BCB7C71CB40DC500C806FE
/* MaterialKeyframeAnimation.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96BCB77E1CB40DC500C806FE
/* MaterialKeyframeAnimation.swift */
;
};
...
...
@@ -134,7 +134,7 @@
96BCB82E1CB4115200C806FE
/* Material+UIImage+Resize.swift in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96BCB76A1CB40DC500C806FE
/* Material+UIImage+Resize.swift */
;
settings
=
{
ATTRIBUTES
=
(
Public
,
);
};
};
96BCB82F1CB4115200C806FE
/* Material+UIImage+Size.swift in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96BCB76B1CB40DC500C806FE
/* Material+UIImage+Size.swift */
;
settings
=
{
ATTRIBUTES
=
(
Public
,
);
};
};
96BCB8301CB4115200C806FE
/* Material+UIImage.swift in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96BCB76C1CB40DC500C806FE
/* Material+UIImage.swift */
;
settings
=
{
ATTRIBUTES
=
(
Public
,
);
};
};
96BCB8311CB4115200C806FE
/*
MaterialFont.swift in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96BCB77B1CB40DC500C806FE
/* Material
Font.swift */
;
settings
=
{
ATTRIBUTES
=
(
Public
,
);
};
};
96BCB8311CB4115200C806FE
/*
Font.swift in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96BCB77B1CB40DC500C806FE
/*
Font.swift */
;
settings
=
{
ATTRIBUTES
=
(
Public
,
);
};
};
96BCB8321CB4115200C806FE
/* RobotoFont.swift in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96BCB7941CB40DC500C806FE
/* RobotoFont.swift */
;
settings
=
{
ATTRIBUTES
=
(
Public
,
);
};
};
96BCB8331CB4115200C806FE
/* Icon.swift in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96BCB77D1CB40DC500C806FE
/* Icon.swift */
;
settings
=
{
ATTRIBUTES
=
(
Public
,
);
};
};
96BCB8341CB4115200C806FE
/* Layer.swift in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96BCB7801CB40DC500C806FE
/* Layer.swift */
;
settings
=
{
ATTRIBUTES
=
(
Public
,
);
};
};
...
...
@@ -244,7 +244,7 @@
96BCB7781CB40DC500C806FE
/* MaterialDepth.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
MaterialDepth.swift
;
sourceTree
=
"<group>"
;
};
96BCB7791CB40DC500C806FE
/* MaterialDevice.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
MaterialDevice.swift
;
sourceTree
=
"<group>"
;
};
96BCB77A1CB40DC500C806FE
/* MaterialEdgeInset.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
MaterialEdgeInset.swift
;
sourceTree
=
"<group>"
;
};
96BCB77B1CB40DC500C806FE
/*
MaterialFont.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
Material
Font.swift
;
sourceTree
=
"<group>"
;
};
96BCB77B1CB40DC500C806FE
/*
Font.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
Font.swift
;
sourceTree
=
"<group>"
;
};
96BCB77C1CB40DC500C806FE
/* MaterialGravity.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
MaterialGravity.swift
;
sourceTree
=
"<group>"
;
};
96BCB77D1CB40DC500C806FE
/* Icon.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
Icon.swift
;
sourceTree
=
"<group>"
;
};
96BCB77E1CB40DC500C806FE
/* MaterialKeyframeAnimation.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
MaterialKeyframeAnimation.swift
;
sourceTree
=
"<group>"
;
};
...
...
@@ -545,7 +545,7 @@
96BCB8071CB4101C00C806FE
/* Font */
=
{
isa
=
PBXGroup
;
children
=
(
96BCB77B1CB40DC500C806FE
/*
Material
Font.swift */
,
96BCB77B1CB40DC500C806FE
/* Font.swift */
,
96BCB7941CB40DC500C806FE
/* RobotoFont.swift */
,
);
name
=
Font
;
...
...
@@ -691,7 +691,7 @@
96BCB82E1CB4115200C806FE
/* Material+UIImage+Resize.swift in Headers */
,
96BCB82F1CB4115200C806FE
/* Material+UIImage+Size.swift in Headers */
,
96BCB8301CB4115200C806FE
/* Material+UIImage.swift in Headers */
,
96BCB8311CB4115200C806FE
/*
Material
Font.swift in Headers */
,
96BCB8311CB4115200C806FE
/* Font.swift in Headers */
,
96BCB8321CB4115200C806FE
/* RobotoFont.swift in Headers */
,
96BCB8331CB4115200C806FE
/* Icon.swift in Headers */
,
96BCB8341CB4115200C806FE
/* Layer.swift in Headers */
,
...
...
@@ -941,7 +941,7 @@
96BCB7D01CB40DC500C806FE
/* InterimSpace.swift in Sources */
,
96BCB7B31CB40DC500C806FE
/* Material+UIImage+Resize.swift in Sources */
,
96BCB7E81CB40DC500C806FE
/* Toolbar.swift in Sources */
,
96BCB7C41CB40DC500C806FE
/*
Material
Font.swift in Sources */
,
96BCB7C41CB40DC500C806FE
/* Font.swift in Sources */
,
96BCB7B41CB40DC500C806FE
/* Material+UIImage+Size.swift in Sources */
,
96BCB7AA1CB40DC500C806FE
/* Grid.swift in Sources */
,
96BCB7E71CB40DC500C806FE
/* TextView.swift in Sources */
,
...
...
Sources/iOS/
Material
Font.swift
→
Sources/iOS/Font.swift
View file @
23c46664
...
...
@@ -30,59 +30,74 @@
import
UIKit
public
protocol
Material
FontType
{}
public
protocol
FontType
{}
public
struct
MaterialFont
:
Material
FontType
{
public
struct
Font
:
FontType
{
/// Size of font.
public
static
let
pointSize
:
CGFloat
=
16
/// Retrieves the system font with a specified size.
/**
Retrieves the system font with a specified size.
- Parameter fontName: A String font name.
*/
public
static
func
systemFontWithSize
(
size
:
CGFloat
)
->
UIFont
{
return
UIFont
.
systemFont
OfSize
(
size
)
return
UIFont
.
systemFont
(
ofSize
:
size
)
}
/// Retrieves the bold system font with a specified size.
/**
Retrieves the bold system font with a specified size..
- Parameter fontName: A String font name.
*/
public
static
func
boldSystemFontWithSize
(
size
:
CGFloat
)
->
UIFont
{
return
UIFont
.
boldSystemFont
OfSize
(
size
)
return
UIFont
.
boldSystemFont
(
ofSize
:
size
)
}
/// Retrieves the italic system font with a specified size.
/**
Retrieves the italic system font with a specified size.
- Parameter fontName: A String font name.
*/
public
static
func
italicSystemFontWithSize
(
size
:
CGFloat
)
->
UIFont
{
return
UIFont
.
italicSystemFont
OfSize
(
size
)
return
UIFont
.
italicSystemFont
(
ofSize
:
size
)
}
/// Loads a font if it is needed.
public
static
func
loadFontIfNeeded
(
fontName
:
String
)
{
MaterialFontLoader
.
loadFontIfNeeded
(
fontName
)
/**
Loads a given font if needed.
- Parameter name: A String font name.
*/
public
static
func
loadFontIfNeeded
(
name
:
String
)
{
FontLoader
.
loadFontIfNeeded
(
name
:
name
)
}
}
/// Loads fonts packaged with Material.
private
class
Material
FontLoader
{
private
class
FontLoader
{
/// A Dictionary of the fonts already loaded.
static
var
loadedFonts
:
Dictionary
<
String
,
String
>
=
Dictionary
<
String
,
String
>
()
/// Loads a font specified if needed.
static
func
loadFontIfNeeded
(
fontName
:
String
)
{
let
loadedFont
:
String
?
=
MaterialFontLoader
.
loadedFonts
[
fontName
]
/**
Loads a given font if needed.
- Parameter fontName: A String font name.
*/
static
func
loadFontIfNeeded
(
name
:
String
)
{
let
loadedFont
:
String
?
=
FontLoader
.
loadedFonts
[
name
]
if
nil
==
loadedFont
&&
nil
==
UIFont
(
name
:
fontN
ame
,
size
:
1
)
{
MaterialFontLoader
.
loadedFonts
[
fontName
]
=
fontN
ame
if
nil
==
loadedFont
&&
nil
==
UIFont
(
name
:
n
ame
,
size
:
1
)
{
FontLoader
.
loadedFonts
[
name
]
=
n
ame
let
bundle
:
NSBundle
=
NSBundle
(
forClass
:
Material
FontLoader
.
self
)
let
identifier
:
String
?
=
bundle
.
bundleIdentifier
let
fontURL
:
NSURL
?
=
true
==
identifier
?
.
hasPrefix
(
"org.cocoapods"
)
?
bundle
.
URLForResource
(
fontName
,
withExtension
:
"ttf"
,
subdirectory
:
"io.cosmicmind.material.fonts.bundle"
)
:
bundle
.
URLForResource
(
fontN
ame
,
withExtension
:
"ttf"
)
let
bundle
=
Bundle
(
for
:
FontLoader
.
self
)
let
identifier
=
bundle
.
bundleIdentifier
let
fontURL
=
true
==
identifier
?
.
hasPrefix
(
"org.cocoapods"
)
?
bundle
.
urlForResource
(
name
,
withExtension
:
"ttf"
,
subdirectory
:
"io.cosmicmind.material.fonts.bundle"
)
:
bundle
.
urlForResource
(
n
ame
,
withExtension
:
"ttf"
)
if
let
v
:
NSURL
=
fontURL
{
let
data
:
NSData
=
NSData
(
contentsOfURL
:
v
)
!
let
provider
:
CGDataProvider
=
CGDataProviderCreateWithCFData
(
data
)
!
let
font
:
CGFont
=
CGFontCreateWithDataProvider
(
provider
)
!
if
let
v
=
fontURL
{
let
data
=
NSData
(
contentsOf
:
v
as
URL
)
!
let
provider
=
CGDataProvider
(
data
:
data
)
!
let
font
=
CGFont
(
provider
)
var
error
:
Unmanaged
<
CFError
>
?
if
!
CTFontManagerRegisterGraphicsFont
(
font
,
&
error
)
{
let
errorDescription
:
CFString
Ref
=
CFErrorCopyDescription
(
error
!.
takeUnretainedValue
())
let
errorDescription
:
CFString
=
CFErrorCopyDescription
(
error
!.
takeUnretainedValue
())
let
nsError
:
NSError
=
error
!.
takeUnretainedValue
()
as
AnyObject
as!
NSError
NSException
(
name
:
NSI
nternalInconsistencyException
,
reason
:
errorDescription
as
String
,
userInfo
:
[
NSUnderlyingErrorKey
:
nsError
])
.
raise
()
NSException
(
name
:
.
i
nternalInconsistencyException
,
reason
:
errorDescription
as
String
,
userInfo
:
[
NSUnderlyingErrorKey
:
nsError
])
.
raise
()
}
}
}
...
...
Sources/iOS/RobotoFont.swift
View file @
23c46664
...
...
@@ -30,79 +30,99 @@
import
UIKit
public
struct
RobotoFont
:
Material
FontType
{
public
struct
RobotoFont
:
FontType
{
/// Size of font.
public
static
var
pointSize
:
CGFloat
{
return
Material
Font
.
pointSize
return
Font
.
pointSize
}
/// Thin font.
public
static
var
thin
:
UIFont
{
return
thinWithSize
(
Material
Font
.
pointSize
)
return
thinWithSize
(
size
:
Font
.
pointSize
)
}
/// Thin with size font.
/// Light font.
public
static
var
light
:
UIFont
{
return
lightWithSize
(
size
:
Font
.
pointSize
)
}
/// Regular font.
public
static
var
regular
:
UIFont
{
return
regularWithSize
(
size
:
Font
.
pointSize
)
}
/// Medium font.
public
static
var
medium
:
UIFont
{
return
mediumWithSize
(
size
:
Font
.
pointSize
)
}
/// Bold font.
public
static
var
bold
:
UIFont
{
return
boldWithSize
(
size
:
Font
.
pointSize
)
}
/**
Thin with size font.
- Parameter size: A CGFLoat for the font size.
- Returns: A UIFont.
*/
public
static
func
thinWithSize
(
size
:
CGFloat
)
->
UIFont
{
MaterialFont
.
loadFontIfNeeded
(
"Roboto-Thin"
)
Font
.
loadFontIfNeeded
(
name
:
"Roboto-Thin"
)
if
let
f
=
UIFont
(
name
:
"Roboto-Thin"
,
size
:
size
)
{
return
f
}
return
MaterialFont
.
systemFontWithSize
(
size
)
return
Font
.
systemFontWithSize
(
size
:
size
)
}
/// Light font.
public
static
var
light
:
UIFont
{
return
lightWithSize
(
MaterialFont
.
pointSize
)
}
/// Light with size font.
/**
Light with size font.
- Parameter size: A CGFLoat for the font size.
- Returns: A UIFont.
*/
public
static
func
lightWithSize
(
size
:
CGFloat
)
->
UIFont
{
MaterialFont
.
loadFontIfNeeded
(
"Roboto-Light"
)
Font
.
loadFontIfNeeded
(
name
:
"Roboto-Light"
)
if
let
f
=
UIFont
(
name
:
"Roboto-Light"
,
size
:
size
)
{
return
f
}
return
MaterialFont
.
systemFontWithSize
(
size
)
}
/// Regular font.
public
static
var
regular
:
UIFont
{
return
regularWithSize
(
MaterialFont
.
pointSize
)
return
Font
.
systemFontWithSize
(
size
:
size
)
}
/// Regular with size font.
/**
Regular with size font.
- Parameter size: A CGFLoat for the font size.
- Returns: A UIFont.
*/
public
static
func
regularWithSize
(
size
:
CGFloat
)
->
UIFont
{
MaterialFont
.
loadFontIfNeeded
(
"Roboto-Regular"
)
Font
.
loadFontIfNeeded
(
name
:
"Roboto-Regular"
)
if
let
f
=
UIFont
(
name
:
"Roboto-Regular"
,
size
:
size
)
{
return
f
}
return
MaterialFont
.
systemFontWithSize
(
size
)
return
Font
.
systemFontWithSize
(
size
:
size
)
}
/// Medium font.
public
static
var
medium
:
UIFont
{
return
mediumWithSize
(
MaterialFont
.
pointSize
)
}
/// Medium with size font.
/**
Medium with size font.
- Parameter size: A CGFLoat for the font size.
- Returns: A UIFont.
*/
public
static
func
mediumWithSize
(
size
:
CGFloat
)
->
UIFont
{
MaterialFont
.
loadFontIfNeeded
(
"Roboto-Medium"
)
Font
.
loadFontIfNeeded
(
name
:
"Roboto-Medium"
)
if
let
f
=
UIFont
(
name
:
"Roboto-Medium"
,
size
:
size
)
{
return
f
}
return
MaterialFont
.
boldSystemFontWithSize
(
size
)
}
/// Bold font.
public
static
var
bold
:
UIFont
{
return
boldWithSize
(
MaterialFont
.
pointSize
)
return
Font
.
boldSystemFontWithSize
(
size
:
size
)
}
/// Bold with size font.
/**
Bold with size font.
- Parameter size: A CGFLoat for the font size.
- Returns: A UIFont.
*/
public
static
func
boldWithSize
(
size
:
CGFloat
)
->
UIFont
{
MaterialFont
.
loadFontIfNeeded
(
"Roboto-Bold"
)
Font
.
loadFontIfNeeded
(
name
:
"Roboto-Bold"
)
if
let
f
=
UIFont
(
name
:
"Roboto-Bold"
,
size
:
size
)
{
return
f
}
return
MaterialFont
.
boldSystemFontWithSize
(
size
)
return
Font
.
boldSystemFontWithSize
(
size
:
size
)
}
}
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