Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dnrops
UIFontComplete
提交
fb64494a
U
UIFontComplete
项目概览
dnrops
/
UIFontComplete
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
UIFontComplete
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
fb64494a
编写于
1月 05, 2022
作者:
M
Mikhail Barashkov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Complete SwiftUI Font support
上级
83dd9002
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
62 addition
and
30 deletion
+62
-30
CHANGELOG.md
CHANGELOG.md
+12
-1
README.md
README.md
+22
-5
Sources/BuiltInFont.swift
Sources/BuiltInFont.swift
+2
-2
Sources/Font+Extension.swift
Sources/Font+Extension.swift
+4
-11
Sources/FontRepresentable.swift
Sources/FontRepresentable.swift
+12
-1
Sources/UIFont+Extension.swift
Sources/UIFont+Extension.swift
+2
-2
Tests/UIFontCompleteTests.swift
Tests/UIFontCompleteTests.swift
+2
-2
UIFontComplete.xcodeproj/project.pbxproj
UIFontComplete.xcodeproj/project.pbxproj
+6
-6
未找到文件。
CHANGELOG.md
浏览文件 @
fb64494a
...
...
@@ -3,7 +3,18 @@
All notable changes to this project will be documented in this file.
`UIFontComplete`
adheres to
[
Semantic Versioning
](
http://semver.org/
)
.
---
---
Draft changelog of 4.0.0
#### Summary
This version adds support for SwiftUI's Font.
## Breaking changes
*
Font renamed to BuiltInFont to avoid naming collision with SwiftUI.
*
Initializing fonts with BuiltInFont now requires you to explicitly specify type: UIFont? or Font.
## [3.0.0](https://github.com/Nirma/UIFontComplete/releases/tag/3.0.0) (01/03/2018)
#### Summary
...
...
README.md
浏览文件 @
fb64494a
...
...
@@ -26,16 +26,16 @@ You can now simply start typing the name of the font enum and let code completio
![](
http://i.imgur.com/yBYRQVB.gif
)
This library currently provides two different options for creating
`UIFont`
objects.
The first is calling the font name off of the provided
`Font`
enumeration and then calling
`of(size:)`
The first is calling the font name off of the provided
`
BuiltIn
Font`
enumeration and then calling
`of(size:)`
to provide the desired size.
```
swif
let myFont
=
Font.helvetica.of(size: 12.0)
```
swif
t
let
myFont
:
UIFont
?
=
BuiltIn
Font
.
helvetica
.
of
(
size
:
12.0
)
```
The other
`UIFont`
creation method offered by this library is similar to the normal
`UIFont`
constructor except that instead of providing a
`String`
of the desired font, a case of the
`Font`
enum is provided instead.
```
swift
let
font
=
UIFont
(
font
:
.
arialBoldItalicMT
,
size
:
12.0
)
```
...
...
@@ -55,6 +55,23 @@ enum CustomFont: String, FontRepresentable {
CustomFont
.
alexBrushRegular
.
of
(
size
:
12.0
)
// => UIFont
```
### SwiftUI support
SwiftUI Font is handled in a same way as UIKit UIFont.
You can do both:
```
swift
let
myFont
:
Font
=
BuiltInFont
.
helvetica
.
of
(
size
:
12.0
)
```
```
swift
let
font
=
Font
(
font
:
.
arialBoldItalicMT
,
size
:
12.0
)
```
## Installation
...
...
Sources/Font.swift
→
Sources/
BuiltIn
Font.swift
浏览文件 @
fb64494a
// Font.swift
//
BuiltIn
Font.swift
// Copyright (c) 2016-2019 Nicholas Maccharoli
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
...
...
@@ -19,7 +19,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
public
enum
Font
:
String
,
FontRepresentable
{
public
enum
BuiltIn
Font
:
String
,
FontRepresentable
{
// ======== ONLY Available in iOS 13+ ========
#if os(iOS)
...
...
Sources/Font+Extension.swift
浏览文件 @
fb64494a
...
...
@@ -19,21 +19,14 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
typealias
UIFontComplete_Font
=
Font
import
CoreGraphics
import
SwiftUI
import
UIKit
@available
(
iOS
13.0
,
*
)
extension
SwiftUI
.
Font
{
@available
(
tvOS
13.0
,
iOS
13.0
,
*
)
extension
Font
{
/// Create a UIFont object with a `Font` enum
init
?(
font
:
UIFontComplete_Font
,
size
:
CGFloat
)
{
let
fontIdentifier
:
String
=
font
.
rawValue
if
let
uiFont
=
UIFont
(
name
:
fontIdentifier
,
size
:
size
)
{
self
.
init
(
uiFont
)
}
else
{
return
nil
}
init
(
font
:
BuiltInFont
,
size
:
CGFloat
)
{
self
=
Font
.
custom
(
font
.
rawValue
,
size
:
size
)
}
}
Sources/FontRepresentable.swift
浏览文件 @
fb64494a
...
...
@@ -19,12 +19,13 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
import
SwiftUI
import
UIKit
public
protocol
FontRepresentable
:
RawRepresentable
{}
extension
FontRepresentable
where
Self
.
RawValue
==
String
{
/// An alternative way to get a particular `UIFont` instance from a `Font`
/// An alternative way to get a particular `UIFont` instance from a `
BuiltIn
Font`
/// value.
///
/// - parameter of size: The desired size of the font.
...
...
@@ -38,4 +39,14 @@ extension FontRepresentable where Self.RawValue == String {
public
func
of
(
size
:
Double
)
->
UIFont
?
{
return
UIFont
(
name
:
rawValue
,
size
:
CGFloat
(
size
))
}
@available
(
tvOS
13.0
,
iOS
13.0
,
*
)
public
func
of
(
size
:
CGFloat
)
->
Font
{
return
Font
.
custom
(
rawValue
,
size
:
size
)
}
@available
(
tvOS
13.0
,
iOS
13.0
,
*
)
public
func
of
(
size
:
Double
)
->
Font
{
return
Font
.
custom
(
rawValue
,
size
:
CGFloat
(
size
))
}
}
Sources/UIFont+Extension.swift
浏览文件 @
fb64494a
// Font+Extension.swift
//
UI
Font+Extension.swift
// Copyright (c) 2016-2019 Nicholas Maccharoli
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
...
...
@@ -23,7 +23,7 @@ import UIKit
extension
UIFont
{
/// Create a UIFont object with a `Font` enum
public
convenience
init
?(
font
:
Font
,
size
:
CGFloat
)
{
public
convenience
init
?(
font
:
BuiltIn
Font
,
size
:
CGFloat
)
{
let
fontIdentifier
:
String
=
font
.
rawValue
self
.
init
(
name
:
fontIdentifier
,
size
:
size
)
}
...
...
Tests/UIFontCompleteTests.swift
浏览文件 @
fb64494a
...
...
@@ -1086,11 +1086,11 @@ class UIFontCompleteTests: XCTestCase {
func
testOfSizeCGFloat
()
{
let
testValue
:
CGFloat
=
12.0
XCTAssertNotNil
(
Font
.
helvetica
.
of
(
size
:
testValue
))
XCTAssertNotNil
(
BuiltIn
Font
.
helvetica
.
of
(
size
:
testValue
))
}
func
testOfSizeDouble
()
{
let
testValue
:
Double
=
12.0
XCTAssertNotNil
(
Font
.
helvetica
.
of
(
size
:
testValue
))
XCTAssertNotNil
(
BuiltIn
Font
.
helvetica
.
of
(
size
:
testValue
))
}
}
UIFontComplete.xcodeproj/project.pbxproj
浏览文件 @
fb64494a
...
...
@@ -10,12 +10,12 @@
4E4C4E8A1FFA0D9400058722
/* UIFontComplete.framework in Frameworks */
=
{
isa
=
PBXBuildFile
;
fileRef
=
4E4C4E811FFA0D9400058722
/* UIFontComplete.framework */
;
};
4E4C4E8F1FFA0D9400058722
/* UIFontComplete_tvOSTests.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
4E4C4E8E1FFA0D9400058722
/* UIFontComplete_tvOSTests.swift */
;
};
4E4C4E911FFA0D9400058722
/* UIFontComplete_tvOS.h in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
4E4C4E831FFA0D9400058722
/* UIFontComplete_tvOS.h */
;
settings
=
{
ATTRIBUTES
=
(
Public
,
);
};
};
4E4C4E981FFA7CDE00058722
/*
Font.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
AA813B551F0092450096ABBD
/*
Font.swift */
;
};
4E4C4E981FFA7CDE00058722
/*
BuiltInFont.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
AA813B551F0092450096ABBD
/* BuiltIn
Font.swift */
;
};
4E4C4E991FFA7CE500058722
/* FontRepresentable.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
AA813B561F0092450096ABBD
/* FontRepresentable.swift */
;
};
4E6A41E11FFA942300DC7D56
/* UIFont+Extension.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
AA813B571F0092450096ABBD
/* UIFont+Extension.swift */
;
};
4E6A41F01FFA95CF00DC7D56
/* UIFontComplete.framework in Frameworks */
=
{
isa
=
PBXBuildFile
;
fileRef
=
4E6A41E71FFA95CF00DC7D56
/* UIFontComplete.framework */
;
};
4E6A41F71FFA95CF00DC7D56
/* UIFontComplete_iOS.h in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
4E6A41E91FFA95CF00DC7D56
/* UIFontComplete_iOS.h */
;
settings
=
{
ATTRIBUTES
=
(
Public
,
);
};
};
4E6A41FE1FFA967900DC7D56
/*
Font.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
AA813B551F0092450096ABBD
/*
Font.swift */
;
};
4E6A41FE1FFA967900DC7D56
/*
BuiltInFont.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
AA813B551F0092450096ABBD
/* BuiltIn
Font.swift */
;
};
4E6A41FF1FFA967D00DC7D56
/* FontRepresentable.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
AA813B561F0092450096ABBD
/* FontRepresentable.swift */
;
};
4E6A42001FFA968100DC7D56
/* UIFont+Extension.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
AA813B571F0092450096ABBD
/* UIFont+Extension.swift */
;
};
4E6A42031FFA96D700DC7D56
/* UIFontCompleteTests.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
AAED536B1F53EEA7009C874C
/* UIFontCompleteTests.swift */
;
};
...
...
@@ -52,7 +52,7 @@
4E6A41EA1FFA95CF00DC7D56
/* Info.plist */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
text.plist.xml
;
path
=
Info.plist
;
sourceTree
=
"<group>"
;
};
4E6A41EF1FFA95CF00DC7D56
/* UIFontComplete-iOSTests.xctest */
=
{
isa
=
PBXFileReference
;
explicitFileType
=
wrapper.cfbundle
;
includeInIndex
=
0
;
path
=
"UIFontComplete-iOSTests.xctest"
;
sourceTree
=
BUILT_PRODUCTS_DIR
;
};
4E6A41F61FFA95CF00DC7D56
/* Info.plist */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
text.plist.xml
;
path
=
Info.plist
;
sourceTree
=
"<group>"
;
};
AA813B551F0092450096ABBD
/*
Font.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
name
=
Font.swift
;
path
=
Sources/
Font.swift
;
sourceTree
=
SOURCE_ROOT
;
};
AA813B551F0092450096ABBD
/*
BuiltInFont.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
name
=
BuiltInFont.swift
;
path
=
Sources/BuiltIn
Font.swift
;
sourceTree
=
SOURCE_ROOT
;
};
AA813B561F0092450096ABBD
/* FontRepresentable.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
name
=
FontRepresentable.swift
;
path
=
Sources/FontRepresentable.swift
;
sourceTree
=
SOURCE_ROOT
;
};
AA813B571F0092450096ABBD
/* UIFont+Extension.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
name
=
"UIFont+Extension.swift"
;
path
=
"Sources/UIFont+Extension.swift"
;
sourceTree
=
SOURCE_ROOT
;
};
AAE1A2A31E02618D00610C40
/* Info.plist */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
text.plist.xml
;
path
=
Info.plist
;
sourceTree
=
"<group>"
;
};
...
...
@@ -97,7 +97,7 @@
136122C41EB2AD2A009F45E4
/* Sources */
=
{
isa
=
PBXGroup
;
children
=
(
AA813B551F0092450096ABBD
/* Font.swift */
,
AA813B551F0092450096ABBD
/*
BuiltIn
Font.swift */
,
AA813B561F0092450096ABBD
/* FontRepresentable.swift */
,
);
name
=
Sources
;
...
...
@@ -370,7 +370,7 @@
buildActionMask
=
2147483647
;
files
=
(
4E6A41E11FFA942300DC7D56
/* UIFont+Extension.swift in Sources */
,
4E4C4E981FFA7CDE00058722
/* Font.swift in Sources */
,
4E4C4E981FFA7CDE00058722
/*
BuiltIn
Font.swift in Sources */
,
C6EAE3222784A32C00315B5C
/* Font+Extension.swift in Sources */
,
4E4C4E991FFA7CE500058722
/* FontRepresentable.swift in Sources */
,
);
...
...
@@ -389,7 +389,7 @@
buildActionMask
=
2147483647
;
files
=
(
4E6A42001FFA968100DC7D56
/* UIFont+Extension.swift in Sources */
,
4E6A41FE1FFA967900DC7D56
/* Font.swift in Sources */
,
4E6A41FE1FFA967900DC7D56
/*
BuiltIn
Font.swift in Sources */
,
C6EAE3212784A32C00315B5C
/* Font+Extension.swift in Sources */
,
4E6A41FF1FFA967D00DC7D56
/* FontRepresentable.swift in Sources */
,
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录