WatchOS5-“图形矩形”并发症图像的大小是多少?

时间:2018-10-13 23:24:47

标签: apple-watch image-scaling apple-watch-complication watch-os-5 clkfullcolorimageprovider

我正在查看this list of complication images for WatchOS5 by Apple,它提到44mm watch上图形矩形并发症的模板为342px×108px(171pt×54pt @ 2x)

我尝试发送342x108图像,但该图像太大-似乎默认缩放模式为"center"。我还尝试了171x54,它太小且太模糊-我在Apple Watch上显示的其他图像更加清晰

图形矩形WatchOS5并发症的正确大小/比例是多少?应用或watchkit /扩展程序是否可以查询可用于并发症的矩形?

    var image: UIImage = UIImage()

    let fileManager = FileManager.default
    do {
        let fileURL = try //...URL of complication file

        let data = try Data(contentsOf: fileURL)
        image = UIImage(data: data)

    } catch {
        image =  UIImage(named: "placeholder") ?? UIImage()
    }

    let textProvider = CLKSimpleTextProvider(text: SessionDelegater.title)
    template.textProvider = textProvider
    template.imageProvider = CLKFullColorImageProvider(fullColorImage: image)

1 个答案:

答案 0 :(得分:1)

部分解决方法-从CGImage手动重新创建图像并分配比例因子2:

        var image: UIImage = UIImage()
        do {
            let fileURL = try FileManager.fileURL("complication")

            let data = try Data(contentsOf: fileURL)
            image = UIImage(data: data) ?? UIImage()
            if let cgImage = image.cgImage {
                  image =  UIImage(cgImage: cgImage, scale: 2, orientation: image.imageOrientation)
            }

        } catch {
            print(error)

            image =  UIImage(named: "image1") ?? UIImage()
        }