Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
1
1weather
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
1weather
Commits
590e2b08
Commit
590e2b08
authored
May 13, 2021
by
Demid Merzlyakov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimization: AppFont main thread impact 5% -> 0.3%.
parent
4c92873d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
8 deletions
+21
-8
1Weather/UI/Helpers/AppFont.swift
+21
-8
No files found.
1Weather/UI/Helpers/AppFont.swift
View file @
590e2b08
...
...
@@ -19,24 +19,37 @@ public struct AppFont {
}
public
struct
SFPro
{
private
static
var
fontCache
=
[
UIFont
.
Weight
:
[
CGFloat
:
UIFont
]]()
static
func
font
(
weigth
:
UIFont
.
Weight
,
size
:
CGFloat
)
->
UIFont
{
if
let
cached
=
fontCache
[
weigth
]?[
size
]
{
return
cached
}
let
descriptor
=
AppFont
.
fontDescriptor
(
size
:
size
,
weight
:
weigth
)
let
font
=
UIFont
(
descriptor
:
descriptor
,
size
:
size
)
if
fontCache
[
weigth
]
==
nil
{
fontCache
[
weigth
]
=
[
size
:
font
]
}
else
{
fontCache
[
weigth
]
!
[
size
]
=
font
}
return
font
}
static
func
regular
(
size
:
CGFloat
)
->
UIFont
{
let
descriptor
=
AppFont
.
fontDescriptor
(
size
:
size
,
weight
:
.
regular
)
return
UIFont
(
descriptor
:
descriptor
,
size
:
size
)
font
(
weigth
:
.
regular
,
size
:
size
)
}
static
func
bold
(
size
:
CGFloat
)
->
UIFont
{
let
descriptor
=
AppFont
.
fontDescriptor
(
size
:
size
,
weight
:
.
bold
)
return
UIFont
(
descriptor
:
descriptor
,
size
:
size
)
font
(
weigth
:
.
bold
,
size
:
size
)
}
static
func
medium
(
size
:
CGFloat
)
->
UIFont
{
let
descriptor
=
AppFont
.
fontDescriptor
(
size
:
size
,
weight
:
.
medium
)
return
UIFont
(
descriptor
:
descriptor
,
size
:
size
)
font
(
weigth
:
.
medium
,
size
:
size
)
}
static
func
semibold
(
size
:
CGFloat
)
->
UIFont
{
let
descriptor
=
AppFont
.
fontDescriptor
(
size
:
size
,
weight
:
.
semibold
)
return
UIFont
(
descriptor
:
descriptor
,
size
:
size
)
font
(
weigth
:
.
semibold
,
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