From 83924987ff125d8e1761864bcaba1db6d49aea4a Mon Sep 17 00:00:00 2001 From: Ryan Nystrom Date: Sat, 20 May 2017 17:10:10 -0400 Subject: [PATCH] calculate text overlay color --- Classes/Views/UIColor+Overlay.swift | 19 +++++++++++++++++++ Freetime.xcodeproj/project.pbxproj | 4 ++++ 2 files changed, 23 insertions(+) create mode 100644 Classes/Views/UIColor+Overlay.swift diff --git a/Classes/Views/UIColor+Overlay.swift b/Classes/Views/UIColor+Overlay.swift new file mode 100644 index 00000000..70513cbd --- /dev/null +++ b/Classes/Views/UIColor+Overlay.swift @@ -0,0 +1,19 @@ +// +// UIColor+Overlay.swift +// Freetime +// +// Created by Ryan Nystrom on 5/20/17. +// Copyright © 2017 Ryan Nystrom. All rights reserved. +// + +import UIKit + +extension UIColor { + + var textOverlayColor: UIColor? { + guard let componentColors = cgColor.components else { return nil } + let brightness = (componentColors[0]*299 + componentColors[1]*587 + componentColors[2]*114) / 1000.0 + return brightness < 0.5 ? .white : .black + } + +} diff --git a/Freetime.xcodeproj/project.pbxproj b/Freetime.xcodeproj/project.pbxproj index f6996faa..bcb5d19e 100644 --- a/Freetime.xcodeproj/project.pbxproj +++ b/Freetime.xcodeproj/project.pbxproj @@ -74,6 +74,7 @@ 29A4769A1ED0AD09005D0953 /* IssueLabelsModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29A476991ED0AD09005D0953 /* IssueLabelsModel.swift */; }; 29A4769C1ED0DEE2005D0953 /* IssueLabelCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29A4769B1ED0DEE2005D0953 /* IssueLabelCell.swift */; }; 29A4769E1ED0E083005D0953 /* Label+IGListDiffable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29A4769D1ED0E083005D0953 /* Label+IGListDiffable.swift */; }; + 29A476A01ED0E6C6005D0953 /* UIColor+Overlay.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29A4769F1ED0E6C6005D0953 /* UIColor+Overlay.swift */; }; 29C0E7071ECBC6C50051D756 /* GithubClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29C0E7061ECBC6C50051D756 /* GithubClient.swift */; }; 29C167671ECA005500439D62 /* Strings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29C167661ECA005500439D62 /* Strings.swift */; }; 29C167691ECA016500439D62 /* EmptyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29C167681ECA016500439D62 /* EmptyView.swift */; }; @@ -210,6 +211,7 @@ 29A476991ED0AD09005D0953 /* IssueLabelsModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IssueLabelsModel.swift; sourceTree = ""; }; 29A4769B1ED0DEE2005D0953 /* IssueLabelCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IssueLabelCell.swift; sourceTree = ""; }; 29A4769D1ED0E083005D0953 /* Label+IGListDiffable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Label+IGListDiffable.swift"; sourceTree = ""; }; + 29A4769F1ED0E6C6005D0953 /* UIColor+Overlay.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIColor+Overlay.swift"; sourceTree = ""; }; 29C0E7061ECBC6C50051D756 /* GithubClient.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GithubClient.swift; sourceTree = ""; }; 29C167661ECA005500439D62 /* Strings.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Strings.swift; sourceTree = ""; }; 29C167681ECA016500439D62 /* EmptyView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EmptyView.swift; sourceTree = ""; }; @@ -434,6 +436,7 @@ 29A195011EC66B8B00C3E289 /* UIColor+Hex.swift */, 298BA08E1EC90FEE00B01946 /* UIView+BottomBorder.swift */, 29A4768D1ED07A23005D0953 /* DateDetailsFormatter.swift */, + 29A4769F1ED0E6C6005D0953 /* UIColor+Overlay.swift */, ); path = Views; sourceTree = ""; @@ -783,6 +786,7 @@ 29C1677F1ECA1D7300439D62 /* SettingsViewController.swift in Sources */, 298BA08B1EC9031E00B01946 /* RepoNotifications+Notification.swift in Sources */, 29C167821ECA4B1C00439D62 /* IssueEvent.swift in Sources */, + 29A476A01ED0E6C6005D0953 /* UIColor+Overlay.swift in Sources */, 29C9FDD61EC65FEE00EE3A52 /* Status.swift in Sources */, 29316DB51ECC7DEB007CAE3F /* CenteredButtonCell.swift in Sources */, 293E147D1ECFE8CF001FB0EB /* IssueCommentModel.swift in Sources */,