Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 18, 2025

The control lacked basic text styling properties, forcing text to use hardcoded sizes and rendering with no spacing from borders.

Changes

  • Added properties

    • FontSize (double, default 14.0) - controls segment text size
    • Padding (Thickness, default 0) - adds spacing around segment content
  • Android

    • Removed hardcoded 12sp from RadioButton layout
    • Map FontSize via SetTextSize() with sp units
    • Map Padding via SetPadding() with pixel conversion
  • iOS/MacCatalyst

    • Apply FontSize through UIStringAttributes.Font for both states
    • Apply Padding via SetContentPositionAdjustment()

Usage

<controls:SegmentedControl 
    FontSize="16" 
    Padding="10,5,10,5"
    TintColor="#007AFF">
  <controls:SegmentedControl.Children>
    <controls:SegmentedControlOption Text="Tab 1" />
    <controls:SegmentedControlOption Text="Tab 2" />
  </controls:SegmentedControl.Children>
</controls:SegmentedControl>
Original prompt

This section details on the original issue you should resolve

<issue_title>Missing a bunch of styling properties</issue_title>
<issue_description>As the title already says, this control lacks a bunch of styling options. It seems like there is no way to set Padding or FontSize for example even tho the control displays text. This way, the text of the control has a different size then everything else in the app and without a padding option for the options, the text is stuck to it's borders which looks ugly. </issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI self-assigned this Nov 18, 2025
Co-authored-by: yurkinh <17849938+yurkinh@users.noreply.github.com>
Copilot AI changed the title [WIP] Add missing styling properties for control Add FontSize and Padding properties to SegmentedControl Nov 18, 2025
Copilot AI requested a review from yurkinh November 18, 2025 14:24
@MykhailoDav MykhailoDav self-assigned this Nov 25, 2025
@MykhailoDav
Copy link
Collaborator

@copilot 'UISegmentedControl' does not contain a definition for 'ContentOffset' and no accessible extension method 'ContentOffset' accepting a first argument of type 'UISegmentedControl' could be found (are you missing a using directive or an assembly reference?)

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds essential text styling capabilities to the SegmentedControl by introducing FontSize and Padding properties, addressing the limitation where text was previously hardcoded and lacked spacing from borders.

  • Added FontSize property (double, default 14.0) for controlling segment text size
  • Added Padding property (Thickness, default 0) for spacing around segment content
  • Implemented platform-specific handlers for Android, iOS, and MacCatalyst with appropriate native mappings

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/Plugin.Maui.SegmentedControl/Control/ISegmentedControl.cs Added FontSize and Padding property declarations to the interface
src/Plugin.Maui.SegmentedControl/Control/SegmentedControl.cs Defined BindableProperty for FontSize and Padding with default values
src/Plugin.Maui.SegmentedControl/Platforms/iOS/SegmentedControlHandler.cs Implemented font size via UIStringAttributes.Font and padding via ContentOffset for iOS
src/Plugin.Maui.SegmentedControl/Platforms/MacCatalyst/SegmentedControlHandler.cs Implemented font size via UIStringAttributes.Font and padding via ContentOffset for MacCatalyst
src/Plugin.Maui.SegmentedControl/Platforms/Android/SegmentedControlHandler.cs Implemented font size via SetTextSize with sp units and padding via SetPadding with pixel conversion
src/Plugin.Maui.SegmentedControl/Platforms/Android/Resources/layout/RadioButton.axml Removed hardcoded 12sp textSize to enable dynamic font sizing
samples/Test.SegmentedControl/MainPage.xaml Added example usage demonstrating FontSize="16" and Padding="10,5,10,5"
README.md Documented new FontSize and Padding properties with descriptions and default values

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 167 to 170
if (OperatingSystem.IsIOSVersionAtLeast(14, 0) || OperatingSystem.IsMacCatalystVersionAtLeast(14, 0))
{
handler.PlatformView.Layer.MasksToBounds = false;
handler.PlatformView.ContentOffset = new CoreGraphics.CGSize(padding.Left - padding.Right, padding.Top - padding.Bottom);
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ContentOffset is intended to shift the content within segments, not to implement padding. Using ContentOffset with (padding.Left - padding.Right, padding.Top - padding.Bottom) will offset content in unexpected ways when padding values differ (e.g., left=10, right=5 produces an offset of 5, not traditional padding). This approach may not provide the expected padding behavior. Consider using UIEdgeInsets via contentEdgeInsets if available, or document this limitation clearly.

Suggested change
if (OperatingSystem.IsIOSVersionAtLeast(14, 0) || OperatingSystem.IsMacCatalystVersionAtLeast(14, 0))
{
handler.PlatformView.Layer.MasksToBounds = false;
handler.PlatformView.ContentOffset = new CoreGraphics.CGSize(padding.Left - padding.Right, padding.Top - padding.Bottom);
// Use ContentEdgeInsets if available (iOS 15+), otherwise do nothing.
if (OperatingSystem.IsIOSVersionAtLeast(15, 0) || OperatingSystem.IsMacCatalystVersionAtLeast(15, 0))
{
handler.PlatformView.Layer.MasksToBounds = false;
handler.PlatformView.ContentEdgeInsets = new UIEdgeInsets(padding.Top, padding.Left, padding.Bottom, padding.Right);

Copilot uses AI. Check for mistakes.
Comment on lines 55 to 58
if (OperatingSystem.IsIOSVersionAtLeast(14, 0) || OperatingSystem.IsMacCatalystVersionAtLeast(14, 0))
{
segmentControl.Layer.MasksToBounds = false;
segmentControl.ContentOffset = new CoreGraphics.CGSize(padding.Left - padding.Right, padding.Top - padding.Bottom);
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ContentOffset is intended to shift the content within segments, not to implement padding. Using ContentOffset with (padding.Left - padding.Right, padding.Top - padding.Bottom) will offset content in unexpected ways when padding values differ (e.g., left=10, right=5 produces an offset of 5, not traditional padding). This approach may not provide the expected padding behavior. Consider using UIEdgeInsets via contentEdgeInsets if available, or document this limitation clearly.

Suggested change
if (OperatingSystem.IsIOSVersionAtLeast(14, 0) || OperatingSystem.IsMacCatalystVersionAtLeast(14, 0))
{
segmentControl.Layer.MasksToBounds = false;
segmentControl.ContentOffset = new CoreGraphics.CGSize(padding.Left - padding.Right, padding.Top - padding.Bottom);
if (OperatingSystem.IsIOSVersionAtLeast(13, 0) || OperatingSystem.IsMacCatalystVersionAtLeast(13, 0))
{
segmentControl.Layer.MasksToBounds = false;
segmentControl.ContentEdgeInsets = new UIEdgeInsets((nfloat)padding.Top, (nfloat)padding.Left, (nfloat)padding.Bottom, (nfloat)padding.Right);

Copilot uses AI. Check for mistakes.
if (OperatingSystem.IsIOSVersionAtLeast(14, 0) || OperatingSystem.IsMacCatalystVersionAtLeast(14, 0))
{
handler.PlatformView.Layer.MasksToBounds = false;
handler.PlatformView.ContentOffset = new CoreGraphics.CGSize(padding.Left - padding.Right, padding.Top - padding.Bottom);
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ContentOffset is intended to shift the content within segments, not to implement padding. Using ContentOffset with (padding.Left - padding.Right, padding.Top - padding.Bottom) will offset content in unexpected ways when padding values differ (e.g., left=10, right=5 produces an offset of 5, not traditional padding). This approach may not provide the expected padding behavior. Consider using UIEdgeInsets via contentEdgeInsets if available, or document this limitation clearly.

Suggested change
handler.PlatformView.ContentOffset = new CoreGraphics.CGSize(padding.Left - padding.Right, padding.Top - padding.Bottom);
handler.PlatformView.ContentEdgeInsets = new UIEdgeInsets((nfloat)padding.Top, (nfloat)padding.Left, (nfloat)padding.Bottom, (nfloat)padding.Right);

Copilot uses AI. Check for mistakes.
Comment on lines 106 to 162
static void MapSelectedTextColor(SegmentedControlHandler handler, SegmentedControl control)
{
handler.PlatformView.SetTitleTextAttributes(new UIStringAttributes() { ForegroundColor = control.SelectedTextColor.ToPlatform() }, UIControlState.Selected);
var font = UIKit.UIFont.SystemFontOfSize((nfloat)control.FontSize);
handler.PlatformView.SetTitleTextAttributes(new UIStringAttributes()
{
ForegroundColor = control.SelectedTextColor.ToPlatform(),
Font = font
}, UIControlState.Selected);
}

static void MapTextColor(SegmentedControlHandler handler, SegmentedControl control)
{
handler.PlatformView.SetTitleTextAttributes(new UIStringAttributes() { ForegroundColor = control.TextColor.ToPlatform() }, UIControlState.Normal);
var font = UIKit.UIFont.SystemFontOfSize((nfloat)control.FontSize);
handler.PlatformView.SetTitleTextAttributes(new UIStringAttributes()
{
ForegroundColor = control.TextColor.ToPlatform(),
Font = font
}, UIControlState.Normal);
}

static void MapFontSize(SegmentedControlHandler handler, SegmentedControl control)
{
var font = UIKit.UIFont.SystemFontOfSize((nfloat)control.FontSize);
handler.PlatformView.SetTitleTextAttributes(new UIStringAttributes()
{
ForegroundColor = control.SelectedTextColor.ToPlatform(),
Font = font
}, UIControlState.Selected);
handler.PlatformView.SetTitleTextAttributes(new UIStringAttributes()
{
ForegroundColor = control.TextColor.ToPlatform(),
Font = font
}, UIControlState.Normal);
}
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] There's significant code duplication between MapFontSize, MapSelectedTextColor, and MapTextColor methods. All three methods create the same font object and call SetTitleTextAttributes with nearly identical code. Consider extracting a helper method like UpdateTitleTextAttributes() that applies both color and font for all states to reduce duplication and make maintenance easier.

Copilot uses AI. Check for mistakes.
Comment on lines 79 to 135
static void MapSelectedTextColor(SegmentedControlHandler handler, SegmentedControl control)
{
handler.PlatformView.SetTitleTextAttributes(new UIStringAttributes() { ForegroundColor = control.SelectedTextColor.ToPlatform() }, UIControlState.Selected);
var font = UIKit.UIFont.SystemFontOfSize((nfloat)control.FontSize);
handler.PlatformView.SetTitleTextAttributes(new UIStringAttributes()
{
ForegroundColor = control.SelectedTextColor.ToPlatform(),
Font = font
}, UIControlState.Selected);
}

static void MapTextColor(SegmentedControlHandler handler, SegmentedControl control)
{
handler.PlatformView.SetTitleTextAttributes(new UIStringAttributes() { ForegroundColor = control.TextColor.ToPlatform() }, UIControlState.Normal);
var font = UIKit.UIFont.SystemFontOfSize((nfloat)control.FontSize);
handler.PlatformView.SetTitleTextAttributes(new UIStringAttributes()
{
ForegroundColor = control.TextColor.ToPlatform(),
Font = font
}, UIControlState.Normal);
}

static void MapFontSize(SegmentedControlHandler handler, SegmentedControl control)
{
var font = UIKit.UIFont.SystemFontOfSize((nfloat)control.FontSize);
handler.PlatformView.SetTitleTextAttributes(new UIStringAttributes()
{
ForegroundColor = control.SelectedTextColor.ToPlatform(),
Font = font
}, UIControlState.Selected);
handler.PlatformView.SetTitleTextAttributes(new UIStringAttributes()
{
ForegroundColor = control.TextColor.ToPlatform(),
Font = font
}, UIControlState.Normal);
}
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] There's significant code duplication between MapFontSize, MapSelectedTextColor, and MapTextColor methods. All three methods create the same font object and call SetTitleTextAttributes with nearly identical code. Consider extracting a helper method like UpdateTitleTextAttributes() that applies both color and font for all states to reduce duplication and make maintenance easier.

Copilot uses AI. Check for mistakes.
if (OperatingSystem.IsIOSVersionAtLeast(14, 0) || OperatingSystem.IsMacCatalystVersionAtLeast(14, 0))
{
segmentControl.Layer.MasksToBounds = false;
segmentControl.ContentOffset = new CoreGraphics.CGSize(padding.Left - padding.Right, padding.Top - padding.Bottom);
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ContentOffset is intended to shift the content within segments, not to implement padding. Using ContentOffset with (padding.Left - padding.Right, padding.Top - padding.Bottom) will offset content in unexpected ways when padding values differ (e.g., left=10, right=5 produces an offset of 5, not traditional padding). This approach may not provide the expected padding behavior. Consider using UIEdgeInsets via contentEdgeInsets if available, or document this limitation clearly.

Suggested change
segmentControl.ContentOffset = new CoreGraphics.CGSize(padding.Left - padding.Right, padding.Top - padding.Bottom);
segmentControl.ContentEdgeInsets = new UIEdgeInsets((nfloat)padding.Top, (nfloat)padding.Left, (nfloat)padding.Bottom, (nfloat)padding.Right);

Copilot uses AI. Check for mistakes.
…tPositionAdjustment

Co-authored-by: MykhailoDav <155299608+MykhailoDav@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 25, 2025

@copilot 'UISegmentedControl' does not contain a definition for 'ContentOffset' and no accessible extension method 'ContentOffset' accepting a first argument of type 'UISegmentedControl' could be foun...

Fixed in de5c038. Replaced ContentOffset (which doesn't exist on UISegmentedControl) with SetContentPositionAdjustment() for iOS and MacCatalyst padding support.

@MykhailoDav MykhailoDav marked this pull request as ready for review November 25, 2025 18:56
@MykhailoDav MykhailoDav merged commit c20d2a2 into main Nov 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing a bunch of styling properties

3 participants