motion-prime/views/view_styler.rb in motion-prime-0.3.0 vs motion-prime/views/view_styler.rb in motion-prime-0.3.1
- old
+ new
@@ -167,22 +167,25 @@
paragrahStyle = NSMutableParagraphStyle.alloc.init
paragrahStyle.setLineSpacing(line_spacing)
attributes[NSParagraphStyleAttributeName] = paragrahStyle
end
-
attributedString = NSAttributedString.alloc.initWithString(value[:text], attributes: attributes)
if underline_range = value[:underline]
attributedString = NSMutableAttributedString.alloc.initWithAttributedString(attributedString)
attributedString.addAttributes({NSUnderlineStyleAttributeName => NSUnderlineStyleSingle}, range: underline_range)
end
-
if view.is_a?(UIButton)
view.setAttributedTitle attributedString, forState: UIControlStateNormal
else
view.attributedText = attributedString
end
-
+ elsif key == 'gradient'
+ gradient = CAGradientLayer.layer
+ gradient.frame = CGRectMake(value[:frame_x].to_f, value[:frame_y].to_f, value[:frame_width].to_f, value[:frame_height].to_f)
+ gradient.colors = value[:colors].map(&:uicolor).map(&:cgcolor)
+ gradient.locations = value[:locations] if value[:locations]
+ view.layer.insertSublayer(gradient, atIndex: 0)
elsif value.is_a?(Hash)
self.class.new(view.send(key.camelize(:lower).to_sym), nil, value).apply
else
view.setValue value, forKey: key.camelize(:lower)
end
\ No newline at end of file