问题描述
我有:api 并且想在数组 weather -> Icon 中显示图标。
目前我只在 iOS 的显示屏上显示此 API 中的字符串,但我看不到图标图像。
我的 MainPage.xaml
看起来像这样:
<Frame CornerRadius="10"
OutlineColor="Red"
Margin="10,10,0"
BackgroundColor="White"
Opacity="0.5">
<StackLayout VerticalOptions="Center">
<Label x:Name="infoLabel"
Grid.ColumnSpan="3"
TextColor="Black"
HorizontalOptions="Center"
FontAttributes="Bold"
FontSize="15" />
<Label x:Name="infoLabel1"
Grid.ColumnSpan="3"
TextColor="Black"
HorizontalOptions="Center"
FontAttributes="Bold"
FontSize="15" />
</StackLayout>
</Frame>
我的 MainPage.xaml.cs
看起来像这样:
string Info = DateDays.DayOfWeek + DateDays.ToString(" MM/dd - HH:mm") + " " + weatherData.weatherForecast[0].Weather.Icon + " " + weatherData.weatherForecast[0].Temperature + "°C";
infoLabel.Text = Info;
string Info1 = DateDays1.DayOfWeek + DateDays1.ToString(" MM/dd - HH:mm") + " " + weatherData.weatherForecast[1].Weather.Icon + " " + weatherData.weatherForecast[1].Temperature + "°C";
infoLabel1.Text = Info1;
结果是:
显示图标的正确方式是什么?
解决方法
您必须将代码“r01n”翻译成网址。见https://www.weatherbit.io/api/codes
<Image Source="https://www.weatherbit.io/static/img/icons/r01n.png" />
你可以像这样构建网址
var url = $"https://www.weatherbit.io/static/img/icons/{weatherData.weatherForecast[0].Weather.Icon}.png";