在 Swift 中使用 CZWeatherKit 让 Climacons 在 UILabel 中显示
Getting Climacons to display in UILabel with CZWeatherKit in Swift
所以我正在使用 CZWeatherKit library to grab weather data from forecast.io。
当我得到结果时,它会发送一个 climacon UInt8 字符,如果 climacon font is installed. I did that but it only shows the char, not the actual icon. Here is the code, it prints a quote i.e. " which is the correct mapping to ClimaconCloudSun, but the icon doesn't show. I followed these instructions 安装 climacons.ttf 字体
,它应该与一个图标匹配
request.sendWithCompletion { (data, error) -> Void in
if let error = error {
print(error)
} else if let weather = data {
let forecast = weather.dailyForecasts.first as! CZWeatherForecastCondition
dispatch_async(dispatch_get_main_queue(), { () -> Void in
// I get back good results, this part works
let avgTempFloat = (forecast.highTemperature.f + forecast.lowTemperature.f) / 2
let avgTemp = NSDecimalNumber(float: avgTempFloat).decimalNumberByRoundingAccordingToBehavior(rounder)
self.temperatureLabel.text = String(avgTemp)
self.weatherLabel.text = forecast.summary
// this part does not work, it has the right char, but does not display icon
// I tried setting self.climaconLabel.font = UIFont(name: "Climacons-Font", size: 30) both in IB and programmatically
let climaChar = forecast.climacon.rawValue
let climaString = NSString(format: "%c", climaChar)
self.climaconLabel.text = String(climaString)
})
}
}
你现在可能已经解决了这个问题,但我会把它留在这里以备将来使用。
将标题文字修改为需要的值后,需要在标签上调用setNeedsLayout
,标签会变为相应的图标。
我解决了完全相同的问题,问题出在字体文件上。将您当前的字体替换为此处提供的字体:https://github.com/comyar/Sol/blob/master/Sol/Sol/Resources/Fonts/Climacons.ttf
所以我正在使用 CZWeatherKit library to grab weather data from forecast.io。
当我得到结果时,它会发送一个 climacon UInt8 字符,如果 climacon font is installed. I did that but it only shows the char, not the actual icon. Here is the code, it prints a quote i.e. " which is the correct mapping to ClimaconCloudSun, but the icon doesn't show. I followed these instructions 安装 climacons.ttf 字体
,它应该与一个图标匹配request.sendWithCompletion { (data, error) -> Void in
if let error = error {
print(error)
} else if let weather = data {
let forecast = weather.dailyForecasts.first as! CZWeatherForecastCondition
dispatch_async(dispatch_get_main_queue(), { () -> Void in
// I get back good results, this part works
let avgTempFloat = (forecast.highTemperature.f + forecast.lowTemperature.f) / 2
let avgTemp = NSDecimalNumber(float: avgTempFloat).decimalNumberByRoundingAccordingToBehavior(rounder)
self.temperatureLabel.text = String(avgTemp)
self.weatherLabel.text = forecast.summary
// this part does not work, it has the right char, but does not display icon
// I tried setting self.climaconLabel.font = UIFont(name: "Climacons-Font", size: 30) both in IB and programmatically
let climaChar = forecast.climacon.rawValue
let climaString = NSString(format: "%c", climaChar)
self.climaconLabel.text = String(climaString)
})
}
}
你现在可能已经解决了这个问题,但我会把它留在这里以备将来使用。
将标题文字修改为需要的值后,需要在标签上调用setNeedsLayout
,标签会变为相应的图标。
我解决了完全相同的问题,问题出在字体文件上。将您当前的字体替换为此处提供的字体:https://github.com/comyar/Sol/blob/master/Sol/Sol/Resources/Fonts/Climacons.ttf