转换API返回的国家/地区的两位数代码,以显示我已保存为.png文件的标记图像

时间:2016-12-05 18:38:10

标签: ios swift api

我正在调用一个返回eSport数据的API - API不返回图像;然而,它确实返回两​​位数的国家代码(即" US" - 对于美国)我在文件中将所有国家/地区标记为.png文件。

有没有办法将API返回的国家/地区代码连接到png文件,并使用图像视图在我的视图控制器上显示png文件?

我的代码:

class MatchViewCell: UITableViewCell {

    @IBOutlet weak var Match: UILabel!
    @IBOutlet weak var MatchDate: UILabel!
    @IBOutlet weak var Match2: UILabel!
    @IBOutlet weak var matchImage: UIImageView!
    @IBOutlet weak var match2Image: UIImageView!



    var match: Match?

    func setupCell(match: Match){
        self.match = match
        let matchDate = match.date
        let dateFormatter = DateFormatter()
        let gregorian = NSCalendar(calendarIdentifier: NSCalendar.Identifier.gregorian)!
        dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ"
        if let date = dateFormatter.date(from: matchDate) {
            dateFormatter.dateFormat = "MM-dd-yyyy, hh:mm a zzz"
            gregorian.timeZone = NSTimeZone.local
            MatchDate.text = dateFormatter.string(from: date)

        }else{
            MatchDate.isHidden = true
        }
        //Match.text =  "\(getParticipant1()) VS. \(getParticipant2())"
        Match.text =  "\(getParticipant1()) VS."
        Match2.text =  "\(getParticipant2())"
        Match.adjustsFontSizeToFitWidth = true

    }

    func getParticipant1() -> String {
        if match?.opponents[0].participants.name != "" {
            return (self.match?.opponents[0].participants.name)!
        } else {
            return "TBD"
        }
    }

    func getParticipant2() -> String {
        if match?.opponents[1].participants.name != "" {
            return (self.match?.opponents[1].participants.name)!
        } else {
            return "TBD"
        }
    }
    func getParticipant1Country() -> String{
        if match?.opponents[0].participants.country != ""{
            return (self.match?.opponents[0].participants.country)!
        }else{
            return "TBD"
        }

}
    func getParticipant2Country() -> String{
        if match?.opponents[1].participants.country != ""{
            return (self.match?.opponents[1].participants.country)!
        }else{
            return "TBD"
        }

}

}

0 个答案:

没有答案