Class: RubyMotionQuery::Font

Inherits:
Object
  • Object
show all
Defined in:
motion/ruby_motion_query/font.rb

Class Method Summary (collapse)

Class Method Details

+ (Object) add_named(key, font_name_or_font, size = nil)

Examples:

# One way to add your own fonts it to open up the Font class and add your own
STANDARD_FONT = 'Helvetica Neue'
def standard_at_size(size);
  UIFont.fontWithName(STANDARD_NAME, size: size)
end
def standard_large ; @standard_large ||= standard_at_size(18) ; end
def standard_medium ; @standard_medium ||= standard_at_size(12) ; end

# Another way is to add named fonts:
RubyMotionQuery::Font.add_named_font :large,  STANDARD_FONT, 44

# In a stylesheet you can just do
font.add_named_font :large,  STANDARD_FONT, 44

# The use like so in your stylesheet:
font = font.large

# The use like so anywhere else:
font = rmq.font.large


38
39
40
41
42
43
44
45
46
47
48
# File 'motion/ruby_motion_query/font.rb', line 38

def add_named(key, font_name_or_font, size = nil)
  font = if font_name_or_font.is_a?(UIFont)
    font_name_or_font
  else
    Font.font_with_name(font_name_or_font, size || 22)
  end

  Font.define_singleton_method(key) do
    font
  end
end

+ (Array) family_list Also known as: family_names

Use this in the console to get a list of font families

Returns:

  • (Array)


64
65
66
# File 'motion/ruby_motion_query/font.rb', line 64

def family_list
  UIFont.familyNames.sort
end

+ (UIFont) font_with_name(name, size) Also known as: with_name

Examples:

font = rmq.font.font_with_name('Helvetica Neue', 18)

Parameters:

  • name (String)

    Name of font

  • size (Float)

    Size of font

Returns:

  • (UIFont)


56
57
58
59
# File 'motion/ruby_motion_query/font.rb', line 56

def font_with_name(name, size)
  # TODO, should rename this to just with_name, so it's rmq.font.with_name
  UIFont.fontWithName(name, size: size)
end

+ (Array) for_family(family)

Returns:

  • (Array)


70
71
72
# File 'motion/ruby_motion_query/font.rb', line 70

def for_family(family)
  UIFont.fontNamesForFamilyName(family)
end

+ (UIFont) system(size = nil)

Returns System font given size

Examples:

font = rmq.font.system(18)

Parameters:

  • size (Float) (defaults to: nil)

Returns:

  • (UIFont)

    System font given size



79
80
81
# File 'motion/ruby_motion_query/font.rb', line 79

def system(size = nil)
  UIFont.systemFontOfSize(size)
end