Search code examples
iosswiftuilabelwebfonts

Getting Climacons to display in UILabel with CZWeatherKit in Swift


So I am using the CZWeatherKit library to grab weather data from forecast.io.

When I get results, it sends a climacon UInt8 char, which should match to an icon if the 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 to install the climacons.ttf font

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)
            })
        }
    }

Solution

  • I solved the exact same issue, the problem was the font file. Replace your current font with the one provided here: https://github.com/comyar/Sol/blob/master/Sol/Sol/Resources/Fonts/Climacons.ttf