How to add space between radio button and radio button text .net maui

Brenda 60 Reputation points
2023-08-31T09:04:06.23+00:00

I have a radio group that looks good in Android but not in iOS. Also, it doesn't take the colour from the resources.

Android

Screenshot 2023-08-31 110233

iOS

2023-08-31_10-58-40-AM

<StackLayout Margin="10">
    <Grid ColumnDefinitions="*,*" RowDefinitions="*,*,*" >
        <RadioButton Grid.Column="0" Grid.ColumnSpan="1" Grid.Row="0" 
					 GroupName="WorkTimeRadioButtons" Content="Example" IsChecked="{Binding ...}" />
        <RadioButton Grid.Column="0" Grid.ColumnSpan="1" Grid.Row="1"
                     GroupName="WorkTimeRadioButtons" Content="Example"
                     IsChecked="{Binding ...}" />
        <RadioButton Grid.Column="0" Grid.ColumnSpan="1" Grid.Row="2"
                     GroupName="WorkTimeRadioButtons" Content="Example"
                     IsChecked="{Binding ...}"/>
        <Frame Grid.Column="1" Grid.RowSpan="3">
            <Entry 
                Text="{Binding ..}"/>
        </Frame>
    </Grid>
</StackLayout>

How can i add space to iOS without changing in Android?

Thanks

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
4,067 questions
0 comments No comments
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 81,191 Reputation points Microsoft External Staff
    2023-09-01T06:20:15.4+00:00

    Hello,

    I have a radio group that looks good in Android but not in iOS. Also, it doesn't take the colour from the resources.

    Yes, I can reproduce this issue, TextColor not working for iOS platform.

    How can i add space to iOS without changing in Android?

    Based on two issues, we can re-define a RadioButton.Content for iOS platform and Android platform.

    For iOS, we can display arbitrary content, add a Label in the RadioButton.Content, set the textcolor and Margin for label

    For Android, we do not make any changes.

    You can refer to the following code.

    <StackLayout Margin="10">
                   <OnPlatform x:TypeArguments="View">
                        <On Platform="iOS">
                            <!-- Use view for iOS here -->
                            <StackLayout Margin="10">
                                <Grid ColumnDefinitions="*,*" RowDefinitions="*,*,*" >
                                    <RadioButton Grid.Column="0" Grid.ColumnSpan="1" Grid.Row="0"
                                                 GroupName="WorkTimeRadioButtons" IsChecked="{Binding .}" >
                                        <RadioButton.Content>
                                            <Label Text="Example" TextColor="DeepSkyBlue" Margin="10,0,0,0" ></Label>
                                        </RadioButton.Content>
                                    </RadioButton>
                                    <RadioButton Grid.Column="0" Grid.ColumnSpan="1" Grid.Row="1"
                                                 GroupName="WorkTimeRadioButtons"
                                                 IsChecked="{Binding .}" >
                                        <RadioButton.Content>
                                            <Label Text="Example" TextColor="DeepSkyBlue" Margin="10,0,0,0" ></Label>
                                        </RadioButton.Content>
                                    </RadioButton>
                                    <RadioButton Grid.Column="0" Grid.ColumnSpan="1" Grid.Row="2"
                                                GroupName="WorkTimeRadioButtons"
                                                IsChecked="{Binding .}">
                                        <RadioButton.Content>
                                            <Label Text="Example" TextColor="DeepSkyBlue" Margin="10,0,0,0" ></Label>
                                        </RadioButton.Content>
                                    </RadioButton>
                                    <Frame Grid.Column="1" Grid.RowSpan="3">
                                        <Entry
                                             Text="{Binding .}"/>
                                    </Frame>
                                </Grid>
                            </StackLayout>
                        </On>
    
    
                        <On Platform="Android">
                           <!-- Use view for Android here -->
                            <StackLayout Margin="10">
                                <Grid ColumnDefinitions="*,*" RowDefinitions="*,*,*" >
                                    <RadioButton Grid.Column="0" Grid.ColumnSpan="1" Grid.Row="0"
                                                 GroupName="WorkTimeRadioButtons" Content="Example" IsChecked="{Binding .}" />
                                    <RadioButton Grid.Column="0" Grid.ColumnSpan="1" Grid.Row="1"
                                                 GroupName="WorkTimeRadioButtons" Content="Example"
                                                 IsChecked="{Binding .}" />
                                    <RadioButton Grid.Column="0" Grid.ColumnSpan="1" Grid.Row="2"
                                                 GroupName="WorkTimeRadioButtons" Content="Example"
                                                 IsChecked="{Binding .}"/>
                                    <Frame Grid.Column="1" Grid.RowSpan="3">
                                        <Entry
                                             Text="{Binding .}"/>
                                    </Frame>
                                </Grid>
                            </StackLayout>
                        </On>
                       
                    </OnPlatform>
                        
                </StackLayout>
    
    

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.