Commit 84eeb69a by Daniel Dahan

added UIFont extension for calculating CGSize of text

parent e4c4ea9a
...@@ -65,6 +65,7 @@ ...@@ -65,6 +65,7 @@
965C17CA1BC82FEF00B1059A /* ImageCardView.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96D26BFC1BC23649006478BD /* ImageCardView.swift */; settings = {ATTRIBUTES = (Public, ); }; }; 965C17CA1BC82FEF00B1059A /* ImageCardView.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96D26BFC1BC23649006478BD /* ImageCardView.swift */; settings = {ATTRIBUTES = (Public, ); }; };
965C17CB1BC82FEF00B1059A /* MaterialCollectionViewCell.swift in Headers */ = {isa = PBXBuildFile; fileRef = 965C17C41BC8273D00B1059A /* MaterialCollectionViewCell.swift */; settings = {ATTRIBUTES = (Public, ); }; }; 965C17CB1BC82FEF00B1059A /* MaterialCollectionViewCell.swift in Headers */ = {isa = PBXBuildFile; fileRef = 965C17C41BC8273D00B1059A /* MaterialCollectionViewCell.swift */; settings = {ATTRIBUTES = (Public, ); }; };
965C17CC1BC82FEF00B1059A /* BasicCollectionViewCell.swift in Headers */ = {isa = PBXBuildFile; fileRef = 965C17C61BC8279F00B1059A /* BasicCollectionViewCell.swift */; settings = {ATTRIBUTES = (Public, ); }; }; 965C17CC1BC82FEF00B1059A /* BasicCollectionViewCell.swift in Headers */ = {isa = PBXBuildFile; fileRef = 965C17C61BC8279F00B1059A /* BasicCollectionViewCell.swift */; settings = {ATTRIBUTES = (Public, ); }; };
9693BF861BCB0E0A0087054A /* Material+UIFont.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9693BF851BCB0E0A0087054A /* Material+UIFont.swift */; settings = {ASSET_TAGS = (); }; };
9699879C1BC5FE49006D678E /* MaterialTextLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9699879B1BC5FE49006D678E /* MaterialTextLayer.swift */; settings = {ASSET_TAGS = (); }; }; 9699879C1BC5FE49006D678E /* MaterialTextLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9699879B1BC5FE49006D678E /* MaterialTextLayer.swift */; settings = {ASSET_TAGS = (); }; };
96C4FABE1BC3168900E4FFC3 /* MaterialTransitionAnimation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96C4FABD1BC3168900E4FFC3 /* MaterialTransitionAnimation.swift */; settings = {ASSET_TAGS = (); }; }; 96C4FABE1BC3168900E4FFC3 /* MaterialTransitionAnimation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96C4FABD1BC3168900E4FFC3 /* MaterialTransitionAnimation.swift */; settings = {ASSET_TAGS = (); }; };
96D26BFD1BC23649006478BD /* ImageCardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D26BFC1BC23649006478BD /* ImageCardView.swift */; settings = {ASSET_TAGS = (); }; }; 96D26BFD1BC23649006478BD /* ImageCardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D26BFC1BC23649006478BD /* ImageCardView.swift */; settings = {ASSET_TAGS = (); }; };
...@@ -120,6 +121,7 @@ ...@@ -120,6 +121,7 @@
964B17D81BBB3911002A9CA0 /* BasicCardView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BasicCardView.swift; sourceTree = "<group>"; }; 964B17D81BBB3911002A9CA0 /* BasicCardView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BasicCardView.swift; sourceTree = "<group>"; };
965C17C41BC8273D00B1059A /* MaterialCollectionViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialCollectionViewCell.swift; sourceTree = "<group>"; }; 965C17C41BC8273D00B1059A /* MaterialCollectionViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialCollectionViewCell.swift; sourceTree = "<group>"; };
965C17C61BC8279F00B1059A /* BasicCollectionViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BasicCollectionViewCell.swift; sourceTree = "<group>"; }; 965C17C61BC8279F00B1059A /* BasicCollectionViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BasicCollectionViewCell.swift; sourceTree = "<group>"; };
9693BF851BCB0E0A0087054A /* Material+UIFont.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Material+UIFont.swift"; sourceTree = "<group>"; };
9699879B1BC5FE49006D678E /* MaterialTextLayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialTextLayer.swift; sourceTree = "<group>"; }; 9699879B1BC5FE49006D678E /* MaterialTextLayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialTextLayer.swift; sourceTree = "<group>"; };
96C4FABD1BC3168900E4FFC3 /* MaterialTransitionAnimation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialTransitionAnimation.swift; sourceTree = "<group>"; }; 96C4FABD1BC3168900E4FFC3 /* MaterialTransitionAnimation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialTransitionAnimation.swift; sourceTree = "<group>"; };
96D26BFC1BC23649006478BD /* ImageCardView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImageCardView.swift; sourceTree = "<group>"; }; 96D26BFC1BC23649006478BD /* ImageCardView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImageCardView.swift; sourceTree = "<group>"; };
...@@ -230,6 +232,7 @@ ...@@ -230,6 +232,7 @@
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
963832631B88E5BF0015F710 /* LICENSE */, 963832631B88E5BF0015F710 /* LICENSE */,
9693BF841BCB0DEE0087054A /* Extensions */,
9638325C1B88E3420015F710 /* Supporting Files */, 9638325C1B88E3420015F710 /* Supporting Files */,
96B57D4C1B90AF6A00DE7BBB /* Theme */, 96B57D4C1B90AF6A00DE7BBB /* Theme */,
9AAC38521B89553800FE6B2D /* Font */, 9AAC38521B89553800FE6B2D /* Font */,
...@@ -305,6 +308,14 @@ ...@@ -305,6 +308,14 @@
name = Collection; name = Collection;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
9693BF841BCB0DEE0087054A /* Extensions */ = {
isa = PBXGroup;
children = (
9693BF851BCB0E0A0087054A /* Material+UIFont.swift */,
);
name = Extensions;
sourceTree = "<group>";
};
96B57D4C1B90AF6A00DE7BBB /* Theme */ = { 96B57D4C1B90AF6A00DE7BBB /* Theme */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
...@@ -497,6 +508,7 @@ ...@@ -497,6 +508,7 @@
65BDD1721BB8CD77006F7F2B /* MaterialLabel.swift in Sources */, 65BDD1721BB8CD77006F7F2B /* MaterialLabel.swift in Sources */,
65BDD1491BB5DC98006F7F2B /* MaterialColor.swift in Sources */, 65BDD1491BB5DC98006F7F2B /* MaterialColor.swift in Sources */,
965C17C71BC8279F00B1059A /* BasicCollectionViewCell.swift in Sources */, 965C17C71BC8279F00B1059A /* BasicCollectionViewCell.swift in Sources */,
9693BF861BCB0E0A0087054A /* Material+UIFont.swift in Sources */,
96C4FABE1BC3168900E4FFC3 /* MaterialTransitionAnimation.swift in Sources */, 96C4FABE1BC3168900E4FFC3 /* MaterialTransitionAnimation.swift in Sources */,
65D2BEC91BBED1FA00800B7B /* MaterialKeyframeAnimation.swift in Sources */, 65D2BEC91BBED1FA00800B7B /* MaterialKeyframeAnimation.swift in Sources */,
65D2BEC71BBED1E400800B7B /* MaterialBasicAnimation.swift in Sources */, 65D2BEC71BBED1E400800B7B /* MaterialBasicAnimation.swift in Sources */,
......
//
// Copyright (C) 2015 GraphKit, Inc. <http://graphkit.io> and other GraphKit contributors.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program located at the root of the software package
// in a file called LICENSE. If not, see <http://www.gnu.org/licenses/>.
//
import UIKit
public extension UIFont {
/**
:name: stringSize
*/
public func stringSize(string: String, constrainedToWidth width: Double) -> CGSize {
return string.boundingRectWithSize(CGSize(width: width, height: DBL_MAX),
options: NSStringDrawingOptions.UsesLineFragmentOrigin,
attributes: [NSFontAttributeName: self],
context: nil).size
}
}
...@@ -18,18 +18,6 @@ ...@@ -18,18 +18,6 @@
import UIKit import UIKit
public extension UIFont {
/**
:name: sizeOfString
*/
public func sizeOfString(string: String, constrainedToWidth width: Double) -> CGSize {
return string.boundingRectWithSize(CGSize(width: width, height: DBL_MAX),
options: NSStringDrawingOptions.UsesLineFragmentOrigin,
attributes: [NSFontAttributeName: self],
context: nil).size
}
}
public class MaterialTextLayer : CATextLayer { public class MaterialTextLayer : CATextLayer {
// //
// :name: internalFont // :name: internalFont
...@@ -150,7 +138,7 @@ public class MaterialTextLayer : CATextLayer { ...@@ -150,7 +138,7 @@ public class MaterialTextLayer : CATextLayer {
public func stringSize(constrainedToWidth width: Double) -> CGSize { public func stringSize(constrainedToWidth width: Double) -> CGSize {
if let v: UIFont = internalFont { if let v: UIFont = internalFont {
if 0 < text?.utf16.count { if 0 < text?.utf16.count {
return v.sizeOfString(text!, constrainedToWidth: width) return v.stringSize(text!, constrainedToWidth: width)
} }
} }
return CGSizeZero return CGSizeZero
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment