Module: BubbleWrap::Font

Defined in:
motion/font/font.rb

Class Method Summary collapse

Class Method Details

.attributes(params = {}) ⇒ Object

I.e. for UINavigationBar#titleTextAttributes



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'motion/font/font.rb', line 69

def attributes(params = {})
  _attributes = {}

  _attributes[UITextAttributeFont] = Font.new(params[:font]) if params[:font]
  _attributes[UITextAttributeTextColor] = params[:color].to_color if params[:color]
  _attributes[UITextAttributeTextShadowColor] = params[:shadow_color].to_color if params[:shadow_color]
  _attributes[UITextAttributeTextShadowOffset] = begin
    x = params[:shadow_offset][:x]
    y = params[:shadow_offset][:y]
    offset = UIOffsetMake(x,y)
    NSValue.valueWithUIOffset(offset)
  end if params[:shadow_offset]

  _attributes
end

.bold(size = nil) ⇒ Object



5
6
7
# File 'motion/font/font.rb', line 5

def bold(size = nil)
  Font.new(:bold, size)
end

.italic(size = nil) ⇒ Object



13
14
15
# File 'motion/font/font.rb', line 13

def italic(size = nil)
  Font.new(:italic, size)
end

.new(params = {}, *args) ⇒ Object Also known as: named

Example Font.new(<# UIFont >) Font.new(“Helvetica”) Font.new(“Helvetica”, 12) Font.new(“Helvetica”, size: 12) Font.new(name: “Helvetica”, size: 12)



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'motion/font/font.rb', line 23

def new(params = {}, *args)
  if params.is_a?(UIFont)
    return params
  end
  _font = nil

  if params.is_a?(NSString)
    params = {name: params}
  end

  if args && !args.empty?
    case args[0]
    when NSDictionary
      params.merge!(args[0])
    else
      params.merge!({size: args[0]})
    end
  end
  params[:size] ||= UIFont.systemFontSize

  case params[:name].to_sym
  when :system
    _font = UIFont.systemFontOfSize(params[:size].to_f)
  when :bold
    _font = UIFont.boldSystemFontOfSize(params[:size].to_f)
  when :italic
    _font = UIFont.italicSystemFontOfSize(params[:size].to_f)
  else
    begin
      _font = UIFont.fontWithName(params[:name], size: params[:size])
    rescue
    end
  end

  if !_font
    raise "Invalid font for parameters: #{params.inspect} args #{args.inspect}"
  end

  _font
end

.system(size = nil) ⇒ Object



9
10
11
# File 'motion/font/font.rb', line 9

def system(size = nil)
  Font.new(:system, size)
end