Skip to content

iOS: let SegmentedControl labels use the TextStyle's fontFamily and the selected style's weight #114

Backlog

Description

@tayormi

Select your plan

Standard - priority support

Confirmations

  • I searched the existing feature requests and this is not a duplicate.

Framework or plugin?

Framework

Platform

iOS

Use case

SegmentedControl's labels can't use the app's font on iOS. Its docs list only fontSize, fontWeight and color for labelFontStyle, and say the selected style's size and weight override the base style "on Android" (lib/src/widgets/segmented_control.dart). On an iPhone, labelFontStyle: TextStyle(fontFamily: 'Manrope') gives SF labels, and the selected segment can't be bolder than the others.

SegmentedControl(
  segments: const ['Arrivals', 'Departures'],
  labelFontStyle: const TextStyle(fontFamily: 'Manrope', fontSize: 14),
  selectedLabelFontStyle: const TextStyle(fontWeight: FontWeight.w800),
  // iOS: SF at the default weight for both segments
);

An app with its own typeface then has one control in the system font. Our workaround is a segmented control drawn in Dart, which means keeping its accessibility and contrast up ourselves. (#69 added icons per segment and pointed to building your own for icon plus text; this one is only about the label font.)

Proposal

On iOS, pass both styles through UISegmentedControl.setTitleTextAttributes(_:for:), for .normal and .selected, with a UIFont built from the TextStyle's fontFamily, fontSize and fontWeight (the same font lookup Text already uses for registered fonts). Then fontFamily works and selectedLabelFontStyle's size and weight apply on both platforms.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions