Swift从Dictionary中分配.setBackgroundImage

时间:2015-01-07 10:14:02

标签: swift ios8

在我项目的plist文件中,我通过字典保存各种图像。 这本词典我可以用两种方式做到:

1)  [mm:photo1, Ed:photo2, as:photo3]

2)  [mm: <UIImage: 0x7fa822540580> size {1024, 768} orientation 0 scale 1.000000, 
     Ed: <UIImage: 0x7fe820474c30> size {1024, 768} orientation 0 scale 1.000000, 
     as: <UIImage: 0x7fe82064d300> size {1024, 768} orientation 0 scale 1.000000]

我可以用这种方式获得钥匙

var ButtonImageReload = data!["ButtonImage"] as? Dictionary<String, String>
            if var b = ButtonImageReload {
                var rek: AnyObject? = b["\(namePlist[index])"]
                newButton .setBackgroundImage(rek, forState: UIControlState.Normal)
                }

我尝试了这种模式2)但是不要去! 我应该如何通过方法1或2保存图像,以及如何将.setBackgroundImage分配给newButton?

UPDATE 我已经解决了1种模式:

var ButtonImageReload = data!["ButtonImage"] as? Dictionary<String, String>
            if var b = ButtonImageReload {
                var rek: AnyObject! = b["\(namePlist[index])"]
                var loadImage = UIImage(named: "\(rek)") as UIImage!
                newButton .setBackgroundImage(loadImage, forState: UIControlState.Normal)

0 个答案:

没有答案