FUIRatingControl

@MainActor
open class FUIRatingControl : UIControl, Initializable, FUIAttributedStringDrawing

FUIRatingControl uses images to represent a rating.

The number of “On” images denotes the rating. The default ‘On’ image is a filled star, while the default ‘Off’ image is an unfilled star. The default ‘Half’ image is a half-filled star when the average rating’s decimal part is between 0.3 and 0.7, inclusive.

When the style property is .editable, user can tap an individual image to set the rating. Users can also slide their finger from side to side over the control to select the rating. The FUIRatingControl will send UIControl.Event.valueChanged event when rating changed.

An optional label displays the formatted average rating value to the left of the images, while another optional label displays the formatted rating value or review count to the right of the images.

Theming

Supported FUIRatingControl class paths:

fdlFUIRatingControl

Supported RatingControl properties:

on-color { -standard | -accented | -editable-disabled | -editable-disabled }: Color;
off-color { -standard | -accented | -editable-disabled | -editable-disabled }: Color;
half-color { -standard | -accented }: Color;
on-image { -standard | -editable }: Image;
off-image { -standard | -editable }: Image;
half-image { -standard | -editable }: Image;

Supported class paths:

fdlFUIRatingControl_leading_label

Supported properties::

font-color: Color
font-name: FontName
font-size: Number
font_style: UIFontTextStyle
font-color { -standard | -accented | -editable-disabled | -editable-disabled }: Color
font-name { -standard | -accented | -editable-disabled | -editable-disabled }: FontName
font-size { -standard | -accented | -editable-disabled | -editable-disabled }: Number
font-style { -standard | -accented | -editable-disabled | -editable-disabled }: UIFontTextStyle

Supported class paths:

fdlFUIRatingControl_trailing_label

Supported properties:

font-color: Color
font-name: FontName
font-size: Number
font_style: UIFontTextStyle
font-color { -standard | -accented | -editable-disabled | -editable-disabled }: Color
font-name { -standard | -accented | -editable-disabled | -editable-disabled }: FontName
font-size { -standard | -accented | -editable-disabled | -editable-disabled }: Number
font-style { -standard | -accented | -editable-disabled | -editable-disabled }: UIFontTextStyle
  • The available style for the FUIRatingControl.

    See more

    Declaration

    Swift

    public enum Style
  • The style of this FUIRatingControl.

    The default is .editable

    Declaration

    Swift

    @MainActor
    open var style: Style { get set }
  • The range of the rating values.

    The default is 0 through 5. This means that there will be 5 images. If rating is 0, all five images will be using the off image.

    Declaration

    Swift

    @MainActor
    open var ratingBounds: ClosedRange<Int> { get set }
  • The rating of this FUIRatingControl.

    The default value is the lower bound of the ratingBounds. less than the lower bound of the ratingBounds.

    • Sets this value below the lower bound of the ratingBounds is interpreted as setting it to the lower bound of the ratingBounds.
    • Sets this value over the upper bound of the ratingBounds is interpreted as setting it to the upper bound of the ratingBounds.

    Declaration

    Swift

    @MainActor
    open var rating: Int { get set }
  • The optional average rating value of this FUIRatingControl can display half-stars in both standard and accented styles. The rating value is used when the average rating value is nil in these styles.“

    If the decimal part of the average rating value is between 0.3 and 0.7, inclusive, a half-star will be shown. For example, a rating of 0.6 will be rounded to 0.5, 0.2 will be rounded to 0, and 0.8 will be rounded to 1.

    • Setting this value below the lower bound of ratingBounds is interpreted as setting it to the lower bound of ratingBounds.

    Declaration

    Swift

    @MainActor
    open var averageRating: Float? { get set }
  • Indicates whether to use a larger size for this control in .standard or .accented style.

    It is used to adjust the size of the image, the spacing of a control’s inner items (such as the space between the leading label and the first image, the space between images, and the space between the last image and the trailing label), and the font style for both the leading and trailing labels.“

    The default value is determined by the style parameter. The default value is set to true when the style parameter is set to .editable or .editableDisabled, and false otherwise. For larger sizes, the space between the control’s items is 8, with an image size of 28 for .editable or .editableDisabled styles, and 20 for .accented or .standard. For other sizes, the space is 6 and the image size is 16.

    Declaration

    Swift

    @MainActor
    open var isLarge: Bool { get set }
  • Indicates whether to display a label with the formatted average rating value to the left of the images. For the larger font sizes, if the content cannot fit on one line, the value will be displayed above the images.

    The possible values for this label are:

    1. The formatted average rating value uses the default format “%.1f” when leadingLabelFormat is nil for accented/standard styles. For example, 3.5.
    2. The formatted rating value uses the default format “%d” when leadingLabelFormat is nil and the optional average rating value is also nil for accented/standard styles. For example, ‘3.

    By default, it was false.

    Declaration

    Swift

    @MainActor
    open var showsLeadingLabel: Bool { get set }
  • Indicates whether to display a label with the formatted review count or rating value to the right of the images. In larger font categories, if the content of the control cannot fit on one line, the value will be displayed below the images.

    The possible values for this label are:

    1. The formatted review count value when reviewCount is not nil or exceeds the review count ceiling value for standard/accent style. For example, ‘9 reviews’ or ‘8+ reviews.’ The default format ‘%d+ reviews’ is used when both reviewCount and reviewCountCeiling are not nil and reviewCount exceeds reviewCountCeiling. In this case, ‘reviews’ is the localized term for ‘reviews,’ and the parameter is the value of reviewCountCeiling. If reviewCountCeiling is nil or reviewCount does not exceed reviewCountCeiling, the format ‘%d reviews’ is used instead, where ‘reviews’ is the localized term, and the parameter is the value of reviewCount.
    2. The formatted rating value with rating bounds count for editable/disabled styles. For example, ‘3 of 5,’ uses the default format ‘%d of %d,’ where “of” is the localized term for “of” when trailingLabelFormat is nil.
    3. When reviewCount is nil and trailingLabelFormat is not nil for standard/accent styles, the average rating value along with the rating bounds count is displayed using trailingLabelFormat. For instance, ‘3.5 of 5’ will be shown when trailingLabelFormat is set to ‘%.1f of %d.’

    By default, it was false.

    Declaration

    Swift

    @MainActor
    open var showsTrailingLabel: Bool { get set }
  • The optional review count of this FUIRatingControl.

    It is used to display the review count information as the value of trailing label. For example, ‘9 reviews’

    Declaration

    Swift

    @MainActor
    open var reviewCount: Int? { get set }
  • The optional review count ceiling of this FUIRatingControl.

    It is used to display the review count as the value of the trailing label when the value of reviewCount exceeds the value of reviewCountCeiling. For example, ‘100+ reviews’.

    Declaration

    Swift

    @MainActor
    open var reviewCountCeiling: Int? { get set }
  • An optional formatter string used to format the value displayed to the left of the images. See showsLeadingLabel for more details.

    Declaration

    Swift

    @MainActor
    open var leadingLabelFormat: String? { get set }
  • An optional formatter string used to format the value displayed to the right of the images. See showsLeadingLabel for more details.

    Declaration

    Swift

    @MainActor
    open var trailingLabelFormat: String? { get set }
  • Indicates whether the rating items need to be wrapped

    By default, it is false, and all the rating item images are displayed in one line

    Declaration

    Swift

    @MainActor
    open var wrapsRatingItems: Bool
  • The maximum number of image is shown in wrapped item row. When the wrapsRatingItems property is set to true, the rating image items will automatically wrap to multiple lines. This property limits the maximum number of images per row. Remaining images will be displayed on the following lines.

    The default is 3. The value should between 1 to ratingBounds.count - 1

    Declaration

    Swift

    @MainActor
    open var maxItemsPerWrapRow: Int { get set }
  • The custom image to be used for “On”.

    If this property is not set, the default filled star image will be used.

    Declaration

    Swift

    @MainActor
    open var onImage: UIImage?
  • The custom image to be used for “Half”.

    If this property is not set, the default half filled star image will be used.

    Declaration

    Swift

    @MainActor
    open var halfImage: UIImage?
  • The custom image to be used for “Off”.

    If this property is not set, the default empty star image will be used.

    Declaration

    Swift

    @MainActor
    open var offImage: UIImage?
  • The custom fixed size of each item image view.

    If this property is not set, the default size is used.

    Declaration

    Swift

    @MainActor
    open var itemSize: CGSize?
  • The custom spacing between item images.

    If this property is not set, the default spacing is used.

    • For styles .standard .accented, the spacing is 6px.
    • For styles .editableEnabled and .editableDisabled, the spacing is 8px.

    Declaration

    Swift

    @MainActor
    open var interItemSpacing: CGFloat?
  • Default constructor.

    Declaration

    Swift

    @MainActor
    public init(style: Style)

    Parameters

    style

    The style for this FUIRatingControl

  • Convenience constructor.

    This constructor is initialized with the .editable style.

    Declaration

    Swift

    @MainActor
    required public convenience init()
  • Sets the tintColor for specified range.

    If developer did not set the tint colors, the default color will be used.

    Declaration

    Swift

    @MainActor
    open func setTintColor(_ color: UIColor, for range: Range<Int>)

    Parameters

    color

    The color to be applied to the item image for both on and off images.

    range

    The range for this color to be applied. Items out of bounds of the ratingBounds will be ignored.

  • Undocumented

    Declaration

    Swift

    @MainActor
    open override func systemLayoutSizeFitting(_ targetSize: CGSize, withHorizontalFittingPriority horizontalFittingPriority: UILayoutPriority, verticalFittingPriority: UILayoutPriority) -> CGSize
  • Undocumented

    Declaration

    Swift

    @MainActor
    override public var keyCommands: [UIKeyCommand]? { get }
  • Undocumented

    Declaration

    Swift

    @MainActor
    open override var accessibilityHint: String? { get set }