NatRating

public final class NatRating : UIView
extension NatRating: Pulsable

Note

This component is available in the following variants:
  • ✅ Counter
  • ✅ Input
  • ✅ Read-only

With the following attribute status:

  • Hint ✅
  • Size:
    • Small
    • Standard
    • Semi
    • SemiX
    • Medium
  • Alignment:
    • Right
    • Left
  • ✅ Disabled
  • ✅ Rate
  • Interaction state:
    • Enabled
    • Press

NatRating is a class that represent the rating component from the design system. The colors are default and doesn’t change according to the current theme configured.

The component has three different variants, represented by the enum Style:

  • Input
  • Counter
  • Read-only

Note

the style should be set at init().

There are five different sizes for the rating stars:

  • Small
  • Standard
  • Semi
  • SemiX (default)
  • Medium

Note

the size can only be changed at init(). The sizes small and standard should only be used with counter and readOnly variants.

Note: For the variant Counter, the alignment can be right or left (default). The aligment should be set at init().

Example of usage:

   let rating = NatRating(style: .input, size: .medium)
   rating.configure(text: "Placeholder")

   let rating = NatRating(style: .counter, alignment: .right)
   rating.configure(text: "Placeholder")

   let rating = NatRating(style: .readOnly)
   rating.configure(rate: 3)

Requires

It’s necessary to configure the Design System with a theme or fatalError will be raised.

   DesignSystem().configure(with: AvailableTheme)
  • Undocumented

    Declaration

    Swift

    public typealias RatingValueHandler = (Int) -> Void

Inits

Touches

  • Undocumented

    Declaration

    Swift

    public override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?)
  • Undocumented

    Declaration

    Swift

    public override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?)

Public methods

  • Sets the text for the hint label (if style is input) or description label (if style is counter). Note: for counter ratings, if the text isn’t set, the component will only display a single colored star.

    Declaration

    Swift

    public func configure(text: String)

    Parameters

    text

    a String with the text to be displayed

  • Sets the rate value to be shown as colored stars in the component. Useful for disabled inputs and readOnly variants.

    Declaration

    Swift

    public func configure(rate: Int)

    Parameters

    rate

    an Int with range from 0 to 5

  • Sets the state for the component. If it’s disabled, the visual style for input variant will be changed.

    Declaration

    Swift

    public func configure(state: State)

    Parameters

    state

    an option from State enum

  • Sets the handler to be executed when the value changes

    Example of usage:

    rating.configure { newValue in }
    

    Declaration

    Swift

    public func configure(valueHandler: @escaping RatingValueHandler)

    Parameters

    valueHandler

    A closure to notify value change

  • A function to get the input value from the used

    Declaration

    Swift

    public func getValue() -> Int

    Return Value

    an Int representing the selected value; range from 1 to 5

  • Alignment represents alignment options for NatRating component (counter).

    These are all alignments allowed for a NatRating:

    • right (default)
    • left

    Note

    alignment configuration apply only to counter style NatRatings. This attribute must be set at init().

    See more

    Declaration

    Swift

    public enum Alignment
  • Size represents size values for NatRating component.

    These are all sizes allowed for a NatRating:

    • small
    • standard
    • semi (default)
    • semiX
    • medium

    Note

    the small and standard sizes should only be applied to counter and readOnly styles.

    See more

    Declaration

    Swift

    public enum Size
  • State represents state options for NatRating component (input).

    These are all states allowed for a NatRating:

    • enabled (default)
    • disabled

    Note

    state configuration apply only to input style NatRatings. This attribute must be set with a configure(state:) method.

    See more

    Declaration

    Swift

    public enum State
  • Style represents variants for NatRating, which apply different structures for the component.

    These are all styles allowed for a NatIconButton:

    • input (has 5 stars and expects an input from the user; can have a hint text label)
    • counter (has 1 star and shows a label with the description for the component)
    • readOnly (has 5 stars and can show a value, only for reading purposes)
    See more

    Declaration

    Swift

    public enum Style