Commit b5ac48a4 by Daniel Dahan

added defaults for MaterialTextLayer

parent 815e678f
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
import UIKit import UIKit
public class MaterialLayer : CAShapeLayer { public class MaterialLayer : CAShapeLayer {
/** /**
:name: init :name: init
*/ */
......
...@@ -19,7 +19,10 @@ ...@@ -19,7 +19,10 @@
import UIKit import UIKit
public extension UIFont { public extension UIFont {
func sizeOfString(string: String, constrainedToWidth width: Double) -> CGSize { /**
:name: sizeOfString
*/
public func sizeOfString(string: String, constrainedToWidth width: Double) -> CGSize {
return string.boundingRectWithSize(CGSize(width: width, height: DBL_MAX), return string.boundingRectWithSize(CGSize(width: width, height: DBL_MAX),
options: NSStringDrawingOptions.UsesLineFragmentOrigin, options: NSStringDrawingOptions.UsesLineFragmentOrigin,
attributes: [NSFontAttributeName: self], attributes: [NSFontAttributeName: self],
...@@ -28,17 +31,14 @@ public extension UIFont { ...@@ -28,17 +31,14 @@ public extension UIFont {
} }
public class MaterialTextLayer : CATextLayer { public class MaterialTextLayer : CATextLayer {
/** //
:name: text // :name: internalFont
*/ //
public var text: String? {
didSet {
string = text as? AnyObject
}
}
private var internalFont: UIFont? private var internalFont: UIFont?
/**
:name: font
*/
public override var font: AnyObject? { public override var font: AnyObject? {
get { get {
return internalFont return internalFont
...@@ -53,25 +53,22 @@ public class MaterialTextLayer : CATextLayer { ...@@ -53,25 +53,22 @@ public class MaterialTextLayer : CATextLayer {
} }
/** /**
:name: pointSize :name: text
*/ */
public var pointSize: CGFloat = 10 { public var text: String? {
didSet { didSet {
fontSize = pointSize string = text as? AnyObject
} }
} }
/** /**
:name: font :name: pointSize
*/ */
// public override var font: AnyObject? { public var pointSize: CGFloat = 10 {
//// didSet { didSet {
//// if let v = font as? UIFont { fontSize = pointSize
//// super.font = CGFontCreateWithFontName(v.fontName as CFStringRef)! }
//// pointSize = v.pointSize }
//// }
//// }
// }
/** /**
:name: textColor :name: textColor
...@@ -169,11 +166,12 @@ public class MaterialTextLayer : CATextLayer { ...@@ -169,11 +166,12 @@ public class MaterialTextLayer : CATextLayer {
// :name: prepareLayer // :name: prepareLayer
// //
internal func prepareLayer() { internal func prepareLayer() {
textColor = MaterialColor.black textColor = MaterialTheme.textLayer.textColor
textAlignment = MaterialTheme.label.textAlignment textAlignment = MaterialTheme.textLayer.textAlignment
wrapped = MaterialTheme.label.wrapped wrapped = MaterialTheme.textLayer.wrapped
contentsScale = MaterialTheme.label.contentsScale contentsScale = MaterialTheme.textLayer.contentsScale
font = MaterialTheme.label.font font = MaterialTheme.textLayer.font
lineBreakMode = MaterialTheme.textLayer.lineBreakMode
} }
} }
...@@ -24,6 +24,7 @@ public struct MaterialTheme { ...@@ -24,6 +24,7 @@ public struct MaterialTheme {
public struct basicCardView {} public struct basicCardView {}
public struct imageCardView {} public struct imageCardView {}
public struct navigationBarView {} public struct navigationBarView {}
public struct textLayer {}
public struct label {} public struct label {}
public struct flatButton {} public struct flatButton {}
public struct raisedButton {} public struct raisedButton {}
...@@ -216,6 +217,23 @@ public extension MaterialTheme.navigationBarView { ...@@ -216,6 +217,23 @@ public extension MaterialTheme.navigationBarView {
public static var zPosition: CGFloat = 100 public static var zPosition: CGFloat = 100
} }
// textLayer
public extension MaterialTheme.textLayer {
// scale
public static var contentsScale: CGFloat = UIScreen.mainScreen().scale
// alignment
public static var wrapped: Bool = true
public static var textAlignment: NSTextAlignment = .Left
public static var lineBreakMode: NSLineBreakMode = .ByWordWrapping
// font
public static var font: UIFont = RobotoFont.regular
// color
public static var textColor: UIColor = MaterialColor.black
}
// label // label
public extension MaterialTheme.label { public extension MaterialTheme.label {
// scale // scale
...@@ -226,7 +244,7 @@ public extension MaterialTheme.label { ...@@ -226,7 +244,7 @@ public extension MaterialTheme.label {
public static var textAlignment: NSTextAlignment = .Left public static var textAlignment: NSTextAlignment = .Left
// font // font
public static var font: UIFont = RobotoFont.regularWithSize(20) public static var font: UIFont = RobotoFont.regular
} }
// flatButton // flatButton
......
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