Skip to content

Commit

Permalink
Refine drawText.
Browse files Browse the repository at this point in the history
  • Loading branch information
lexrus committed Aug 24, 2017
1 parent 8bb2974 commit 7397b6f
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 14 deletions.
6 changes: 4 additions & 2 deletions LTMorphingLabel/LTMorphingLabel+Sparkle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,17 @@ extension LTMorphingLabel {
NSFontAttributeName: self.font,
NSForegroundColorAttributeName: self.textColor
])
let newImage = UIGraphicsGetImageFromCurrentImageContext()
guard let newImage = UIGraphicsGetImageFromCurrentImageContext() else {
return (UIImage(), CGRect.zero)
}
UIGraphicsEndImageContext()
let newRect = CGRect(
x: charLimbo.rect.origin.x,
y: charLimbo.rect.origin.y,
width: charLimbo.rect.size.width,
height: maskedHeight
)
return (newImage!, newRect)
return (newImage, newRect)
}

func SparkleLoad() {
Expand Down
20 changes: 11 additions & 9 deletions LTMorphingLabel/LTMorphingLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ typealias LTMorphingSkipFramesClosure =

override open var font: UIFont! {
get {
return super.font
return super.font ?? UIFont.systemFont(ofSize: 15)
}
set {
super.font = newValue
Expand All @@ -121,7 +121,7 @@ typealias LTMorphingSkipFramesClosure =

override open var text: String! {
get {
return super.text
return super.text ?? ""
}
set {
guard text != newValue else { return }
Expand Down Expand Up @@ -489,15 +489,17 @@ extension LTMorphingLabel {
}
return false
}(charLimbo)

if !willAvoidDefaultDrawing {
var attrs: [String: Any] = [
NSForegroundColorAttributeName: textColor.withAlphaComponent(charLimbo.alpha)
]

if let font = UIFont(name: font.fontName, size: charLimbo.size) {
attrs[NSFontAttributeName] = font
}
let s = String(charLimbo.char)
s.draw(in: charRect, withAttributes: [
NSFontAttributeName:
UIFont.init(name: font.fontName, size: charLimbo.size)!,
NSForegroundColorAttributeName:
textColor.withAlphaComponent(charLimbo.alpha)
])
s.draw(in: charRect, withAttributes: attrs)
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion LTMorphingLabelDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@
attributes = {
LastSwiftMigration = 0700;
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0800;
LastUpgradeCheck = 0830;
ORGANIZATIONNAME = lexrus.com;
TargetAttributes = {
D74AD96D195171E7009A2ACD = {
Expand Down Expand Up @@ -575,6 +575,7 @@
isa = XCBuildConfiguration;
buildSettings = {
APPLICATION_EXTENSION_API_ONLY = YES;
"CODE_SIGN_IDENTITY[sdk=appletvos*]" = "";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
CURRENT_PROJECT_VERSION = 1;
DEFINES_MODULE = YES;
Expand Down Expand Up @@ -606,6 +607,7 @@
isa = XCBuildConfiguration;
buildSettings = {
APPLICATION_EXTENSION_API_ONLY = YES;
"CODE_SIGN_IDENTITY[sdk=appletvos*]" = "";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
CURRENT_PROJECT_VERSION = 1;
DEFINES_MODULE = YES;
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0800"
LastUpgradeVersion = "0830"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0800"
LastUpgradeVersion = "0830"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down

0 comments on commit 7397b6f

Please sign in to comment.