Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. // Can use - border-bottom : "purple,3"
  2. // Can use - border-bottom : "#444, 3"
  3. // etc
  4.  
  5. conf.interpreter.map(UILabel.self, forAttributeKey: "border-bottom", withType:Borderized.self) {
  6. let key = $0.key.appending("C-")
  7.  
  8. let layer = $0.component.layer.sublayers?.lazy.filter { $0.name == key }.first ?? CALayer()
  9.  
  10. layer.frame = $0.component.frame
  11. layer.name = key
  12. layer.frame.size.height = CGFloat($0.value.width)
  13. layer.backgroundColor = $0.value.color.cgColor
  14. layer.frame = layer.frame.offsetBy(dx: 0, dy: $0.component.intrinsicContentSize.height)
  15. $0.component.layer.addSublayer(layer)
  16. $0.component.layer.masksToBounds = false
  17. }
  18.  
  19.  
  20. conf.lexer.type.tokenize(from: String.self, to: Borderized.self) {
  21. let list = $0.inputValue.components(separatedBy: ",").flatMap {$0.trimmingCharacters(in: .whitespacesAndNewlines) }
  22. guard let color = list.first, let width = list.last else { return nil }
  23.  
  24. let c:UIColor? = conf.lexer.type.scan(withValue: color)
  25. let w:Double? = conf.lexer.type.scan(withValue: width)
  26. return Borderized(color: c, width: w)
  27.  
  28. }
  29.  
  30.  
  31.  
  32. struct Borderized {
  33. let color: UIColor
  34. let width: Double
  35. init?(color:UIColor?, width:Double?) {
  36. guard let c = color, let w = width else { return nil }
  37. self.color = c
  38. self.width = w
  39. }
  40. }
  41.  
  42. extension Borderized : InterpreterValue { }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement