@@ -2,7 +2,8 @@ import { Font } from '../styling/font';
22import { SegmentedBarItemBase , SegmentedBarBase , selectedIndexProperty , itemsProperty , selectedBackgroundColorProperty } from './segmented-bar-common' ;
33import { colorProperty , fontInternalProperty } from '../styling/style-properties' ;
44import { Color } from '../../color' ;
5- import { iOSNativeHelper } from '../../utils' ;
5+ import { Trace } from '../../trace' ;
6+ import { SDK_VERSION } from '../../utils' ;
67export * from './segmented-bar-common' ;
78
89export class SegmentedBarItem extends SegmentedBarItemBase {
@@ -68,14 +69,11 @@ export class SegmentedBar extends SegmentedBarBase {
6869 }
6970
7071 [ selectedBackgroundColorProperty . getDefault ] ( ) : UIColor {
71- const currentOsVersion = iOSNativeHelper . MajorVersion ;
72-
73- return currentOsVersion < 13 ? this . ios . tintColor : this . ios . selectedSegmentTintColor ;
72+ return SDK_VERSION < 13 ? this . ios . tintColor : this . ios . selectedSegmentTintColor ;
7473 }
7574 [ selectedBackgroundColorProperty . setNative ] ( value : UIColor | Color ) {
76- const currentOsVersion = iOSNativeHelper . MajorVersion ;
7775 const color = value instanceof Color ? value . ios : value ;
78- if ( currentOsVersion < 13 ) {
76+ if ( SDK_VERSION < 13 ) {
7977 this . ios . tintColor = color ;
8078 } else {
8179 this . ios . selectedSegmentTintColor = color ;
@@ -92,6 +90,8 @@ export class SegmentedBar extends SegmentedBarBase {
9290 const attrs = currentAttrs ? currentAttrs . mutableCopy ( ) : NSMutableDictionary . new ( ) ;
9391 attrs . setValueForKey ( color , NSForegroundColorAttributeName ) ;
9492 bar . setTitleTextAttributesForState ( attrs , UIControlState . Normal ) ;
93+ // Set the selected text color
94+ this . setSelectedTextColor ( bar ) ;
9595 }
9696
9797 [ fontInternalProperty . getDefault ] ( ) : Font {
@@ -105,6 +105,27 @@ export class SegmentedBar extends SegmentedBarBase {
105105 attrs . setValueForKey ( font , NSFontAttributeName ) ;
106106 bar . setTitleTextAttributesForState ( attrs , UIControlState . Normal ) ;
107107 }
108+ setSelectedTextColor ( bar : UISegmentedControl ) {
109+ try {
110+ const selectedTextColor = this . getColorForIOS ( this ?. selectedTextColor ?? this ?. color ?? '#000000' ) ;
111+ if ( ! selectedTextColor ) {
112+ Trace . write ( `unable te set selectedTextColor` , Trace . categories . Error ) ;
113+ }
114+ const selectedText = bar . titleTextAttributesForState ( UIControlState . Selected ) ;
115+ const attrsSelected = selectedText ? selectedText . mutableCopy ( ) : NSMutableDictionary . new ( ) ;
116+ attrsSelected . setValueForKey ( selectedTextColor , NSForegroundColorAttributeName ) ;
117+ bar . setTitleTextAttributesForState ( attrsSelected , UIControlState . Selected ) ;
118+ } catch ( e ) {
119+ console . error ( `SegmentedBar:` , e ) ;
120+ }
121+ }
122+ private getColorForIOS ( color : string | Color ) : UIColor {
123+ if ( typeof color === 'string' ) {
124+ return new Color ( color ) . ios ;
125+ } else if ( color instanceof Color ) {
126+ return color . ios ;
127+ }
128+ }
108129}
109130
110131@NativeClass
@@ -122,6 +143,7 @@ class SelectionHandlerImpl extends NSObject {
122143 const owner = this . _owner ?. deref ( ) ;
123144 if ( owner ) {
124145 owner . selectedIndex = sender . selectedSegmentIndex ;
146+ owner . setSelectedTextColor ( sender ) ;
125147 }
126148 }
127149
0 commit comments