Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Xcode 9.4.1 seems to break Styles on iOS

$
0
0

I've upgraded from Xcode 9.2 to Xcode 9.4.1, and am finding that Styles defined in my App.xaml no longer work. There is a workaround, which is to create an OnPlatform resource for each setter. However, this is clearly not optimal!

Has anyone else observed this and got a better fix? It should also be logged as a bug I think. There is a similar bug here on GitHub.

It could be an iOS version problem - I'm using different simulators for the two Xcode versions, iOS 11.2 for Xcode 9.2 and iOS 11.4 for Xcode 9.4.1. I haven't tried changing simulators yet.

Edit - This is with Forms version 2.5.0.121934 and Xamarin.iOS version 11.12.0.4

Code to reproduce it is below.

App.XAML:

<Application.Resources>
        <ResourceDictionary>
            <OnPlatform
                x:Key          ="ButtonBackgroundColor"
                x:TypeArguments="Color"
                Android        ="#ff0180a5"
                iOS            ="#ff0180a5"
                WinPhone       ="#ff0180a5" />
            <OnPlatform
                x:Key          ="ButtonTextColor"
                x:TypeArguments="Color"
                Android        ="White"
                iOS            ="White"
                WinPhone       ="White" />
            <Style
                x:Key     ="StyleButtonWithPlatformSetters"
                TargetType="Button">
                <Setter
                    Property="TextColor"
                    Value   ="{StaticResource ButtonTextColor}" />
                <Setter
                    Property="BackgroundColor"
                    Value   ="{StaticResource ButtonBackgroundColor}" />
            </Style>
            <Style
                x:Key     ="StyleButtonWithPlainSetters"
                TargetType="Button">
                <Setter
                    Property="TextColor"
                    Value   ="White" />
                <Setter
                    Property="BackgroundColor"
                    Value   ="#ff0180a5" />
            </Style>
            <OnPlatform
                x:Key          ="LabelBackgroundColor"
                x:TypeArguments="Color"
                Android        ="Red"
                iOS            ="Red"
                WinPhone       ="Red" />
            <Style
                x:Key     ="StyleLabelWithPlatformSetters"
                TargetType="Label">
                <Setter
                    Property="BackgroundColor"
                    Value   ="{StaticResource LabelBackgroundColor}" />
            </Style>
            <Style
                x:Key     ="StyleLabelWithPlainSetters"
                TargetType="Label">
                <Setter
                    Property="BackgroundColor"
                    Value   ="Red" />
            </Style>
        </ResourceDictionary>
    </Application.Resources>

Page:

    <ContentPage.Content>
        <StackLayout>
            <Label
                HorizontalOptions="Center"
                Style            ="{StaticResource StyleLabelWithPlainSetters}"
                Text             ="Label with plain setters" />
            <Button
                Style       ="{StaticResource StyleButtonWithPlainSetters}"
                Grid.Column ="0"
                Margin      ="20"
                WidthRequest="100"
                Text        ="Show Products"
                Command     ="{Binding ButtonClickCommand}" />
            <Label
                HorizontalOptions="Center"
                Style            ="{StaticResource StyleLabelWithPlatformSetters}"
                Text             ="Label with OnPlatform setters" />
            <Button
                Style       ="{StaticResource StyleButtonWithPlatformSetters}"
                Grid.Column ="0"
                Margin      ="20"
                WidthRequest="100"
                Text        ="Show Products"
                Command     ="{Binding ButtonClickCommand}" />
        </StackLayout>
    </ContentPage.Content>

Result using Xcode 9.4.1 - the top label and button don't use OnPlatform

Result using Xcode 9.2


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>