昨天我们已经能成功选择天气预报想查看的地点和时间了
App上的资讯也会随着UIPickerView的选择而做改变
但这样看起来好像还有点不完美,所以我们打算增加天气图示以及让背景图片能根据目前天气而改变,这样能让我们更了解现在的天气状况!
首先,我们先拉好两个UIImageView并拉好@IBOutlet
接着将所需要用到的背景图片放到Assets.xcassets里面
至於天气图示是使用Xcode内建的图片,如果不知道图片名称,可以到这里搜寻看看
再来写一个function来判断Wx天气现象的文字里面是否有包含关键字让天气图示与背景图片做出相对应的改变
func changeWeatherImage() {
if wx.text!.contains("积冰") {
weatherImage.image = UIImage.init(systemName: "snow")
backgroundImage.image = UIImage(named: "snowground")
}
else if wx.text!.contains("暴风雪"){
weatherImage.image = UIImage.init(systemName: "wind.snow")
backgroundImage.image = UIImage(named: "brizzard")
}
else if wx.text!.contains("雪") {
if wx.text!.contains("雨") {
weatherImage.image = UIImage.init(systemName: "cloud.sleet")
backgroundImage.image = UIImage(named: "sleet")
}
else {
weatherImage.image = UIImage.init(systemName: "cloud.snow")
backgroundImage.image = UIImage(named: "snow")
}
}
else if wx.text!.contains("雨") {
if wx.text!.contains("雷") {
weatherImage.image = UIImage.init(systemName: "cloud.bolt.rain")
backgroundImage.image = UIImage(named: "thunder rain")
}
else if wx.text!.contains("晴"){
weatherImage.image = UIImage.init(systemName: "cloud.sun.rain")
backgroundImage.image = UIImage(named: "sun cloud rain")
}
else {
weatherImage.image = UIImage.init(systemName: "cloud.rain")
backgroundImage.image = UIImage(named: "rain")
}
}
else if wx.text!.contains("晴") {
if wx.text!.contains("云") {
weatherImage.image = UIImage.init(systemName: "cloud.sun")
backgroundImage.image = UIImage(named: "cloud and sun")
}
else {
weatherImage.image = UIImage.init(systemName: "sun.max")
backgroundImage.image = UIImage(named: "sun")
}
}
else if wx.text!.contains("阴") {
weatherImage.image = UIImage.init(systemName: "smoke.fill")
backgroundImage.image = UIImage(named: "cloudy day")
}
else if wx.text!.contains("云") {
weatherImage.image = UIImage.init(systemName: "smoke")
backgroundImage.image = UIImage(named: "cloud")
}
}
执行结果如下
如此一来我们的天气App就完成啦!
<<: [C 语言笔记--Day25] fork() 的小小练习
根据官方说明,因为历史资料的查询蛮耗资源的,有可能会拖慢系统的速度,所以官方不建议使用,而且有每5秒...
待更新待更新待更新待更新待更新待更新待更新待更新待更新待更新待更新待更新待更新待更新待更新待更新待更...
昨天我们已经将前置作业,也就是 URL Types、AppDelegate.swift 完成了,今天...
今天教大家一个简单免费的方式来享受YouTube後台播放。 只需 3 个简单的步骤,即可在 iOS ...
作业系统L6-同步 临界区间(critical section) 每一行程中的部分程序码,可以共同改...