Commit 7e12ec6e by Daniel Dahan

experimental: added textAlignment to MaterialLabel

parent 1986b113
...@@ -64,6 +64,26 @@ public class MaterialLabel : UILabel { ...@@ -64,6 +64,26 @@ public class MaterialLabel : UILabel {
} }
/** /**
:name: textAlignment
*/
public override var textAlignment: NSTextAlignment {
didSet {
switch textAlignment {
case .Left:
textLayer.alignmentMode = kCAAlignmentLeft
case .Center:
textLayer.alignmentMode = kCAAlignmentCenter
case .Right:
textLayer.alignmentMode = kCAAlignmentRight
case .Justified:
textLayer.alignmentMode = kCAAlignmentJustified
case .Natural:
textLayer.alignmentMode = kCAAlignmentNatural
}
}
}
/**
:name: init :name: init
*/ */
public required init?(coder aDecoder: NSCoder) { public required init?(coder aDecoder: NSCoder) {
......
...@@ -19,6 +19,11 @@ ...@@ -19,6 +19,11 @@
import UIKit import UIKit
public class NavigationBarView: MaterialView { public class NavigationBarView: MaterialView {
//
// :name: isLoading
//
internal lazy var isLoading: Bool = false
/** /**
:name: statusBarStyle :name: statusBarStyle
*/ */
...@@ -40,17 +45,22 @@ public class NavigationBarView: MaterialView { ...@@ -40,17 +45,22 @@ public class NavigationBarView: MaterialView {
/** /**
:name: contentInsetsRef :name: contentInsetsRef
*/ */
public var contentInsetsRef: MaterialInsetsType! public var contentInsetsRef: MaterialInsetsType! {
didSet {
reloadView()
}
}
/** /**
:name: titleLabel :name: titleLabel
*/ */
public var titleLabel: MaterialLabel? { public var titleLabel: UILabel? {
didSet { didSet {
if let v = titleLabel { if let v = titleLabel {
v.translatesAutoresizingMaskIntoConstraints = false v.translatesAutoresizingMaskIntoConstraints = false
addSubview(v) addSubview(v)
} }
reloadView()
} }
} }
...@@ -78,28 +88,36 @@ public class NavigationBarView: MaterialView { ...@@ -78,28 +88,36 @@ public class NavigationBarView: MaterialView {
/** /**
:name: init :name: init
*/ */
public convenience init?(titleLabel: MaterialLabel? = nil) { public convenience init?(titleLabel: UILabel? = nil) {
self.init(frame: CGRectMake(MaterialTheme.navigation.x, MaterialTheme.navigation.y, MaterialTheme.navigation.width, MaterialTheme.navigation.height)) self.init(frame: CGRectMake(MaterialTheme.navigation.x, MaterialTheme.navigation.y, MaterialTheme.navigation.width, MaterialTheme.navigation.height))
self.prepareProperties(titleLabel) self.prepareProperties(titleLabel)
} }
/** /**
:name: layoutSubviews :name: reloadView
*/ */
public override func layoutSubviews() { public func reloadView() {
super.layoutSubviews() if false == isLoading && nil != contentInsetsRef {
isLoading = true
if nil != contentInsetsRef {
// clear constraints so new ones do not conflict
removeConstraints(constraints) removeConstraints(constraints)
MaterialLayout.alignToParentHorizontallyWithPad(self, child: titleLabel!, left: contentInsetsRef!.left, right: contentInsetsRef!.right)
MaterialLayout.alignFromBottom(self, child: titleLabel!, bottom: contentInsetsRef!.bottom) if nil != titleLabel {
MaterialLayout.alignToParentHorizontallyWithPad(self, child: titleLabel!, left: contentInsetsRef!.left, right: contentInsetsRef!.right)
MaterialLayout.alignFromBottom(self, child: titleLabel!, bottom: contentInsetsRef!.bottom)
}
isLoading = false
} }
} }
// //
// :name: prepareProperties // :name: prepareProperties
// //
internal func prepareProperties(titleLabel: MaterialLabel?) { internal func prepareProperties(titleLabel: UILabel?) {
self.titleLabel = titleLabel self.titleLabel = titleLabel
} }
......
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