代码之家  ›  专栏  ›  技术社区  ›  K.K.D

我应该为iOS应用程序准备多大的基本图像大小?

  •  1
  • K.K.D  · 技术社区  · 8 年前

    我是一个iOS开发者,通常使用Swift。最近我在想iOS应用程序的基本图像大小应该是多少。

    我应该使用哪种尺寸的图像?

    我使用背景图像和其他对象(6个正方形),当使用iphone6s和iphonex时,它的外观会因设备而异。

    iPhone 6s iPhone X

    class Constants {
    
        //width of base design size
        static let guiPartsWidthOnDesign = CGFloat(750.0)
    
        //ratio for layout
        static var guiPartsMultiplier: CGFloat = UIScreen.main.bounds.width / (Constants.guiPartsWidthOnDesign / 2.0)
    
        //detect safe area
        static let safeArea = UIApplication.shared.delegate?.window??.safeAreaInsets.bottom
    
    }
    
    class ViewController: UIViewController {
    
        override func viewDidLoad() {
            super.viewDidLoad()
    
        self.view.frame = CGRect(x: 0,
                                 y: 0,
                                 width: self.view.frame.size.width,
                                 height: self.view.frame.size.height)
    
            //backgrond
            let background = UIImageView.init(frame: UIScreen.main.bounds)
            background.center.x = self.view.frame.size.width/2
            background.image = UIImage(named:"BG")
            background.contentMode = UIViewContentMode.scaleAspectFill
            self.view.insertSubview(background, at: 0)
    
            //downleft blue button
            let blueButton = UIImageView.init(frame: CGRect(
                x: 64/2*Constants.guiPartsMultiplier,
                y: self.view.frame.size.height-(52/2+34/2)*Constants.guiPartsMultiplier-Constants.safeArea!,
                width: 60/2*Constants.guiPartsMultiplier,
                height: 52/2*Constants.guiPartsMultiplier))
            self.view.addSubview(blueButton)
            blueButton.backgroundColor = UIColor.blue
    
            //green button
            let greenButton = UIImageView.init(frame: CGRect(
                x: (60/2+64/2+128/2)*Constants.guiPartsMultiplier,
                y: self.view.frame.size.height-(52/2+34/2)*Constants.guiPartsMultiplier-Constants.safeArea!,
                width: 60/2*Constants.guiPartsMultiplier,
                height: 52/2*Constants.guiPartsMultiplier))
            self.view.addSubview(greenButton)
            greenButton.backgroundColor = UIColor.green
    
            //cyan button
            let cyanButton = UIImageView.init(frame: CGRect(
                x: (64/2+(60/2)*2+(128/2*2))*Constants.guiPartsMultiplier,
                y: self.view.frame.size.height-(52/2+34/2)*Constants.guiPartsMultiplier-Constants.safeArea!,
                width: 60/2*Constants.guiPartsMultiplier,
                height: 52/2*Constants.guiPartsMultiplier))
            self.view.addSubview(cyanButton)
            cyanButton.backgroundColor = UIColor.cyan
    
            //4 blue buttons
            for i in 1..<5 {
                let subBlueButton = UIImageView.init(frame: CGRect(
                    x: 64/2*Constants.guiPartsMultiplier,
                    y: self.view.frame.size.height-((43.0+CGFloat(50*i))*Constants.guiPartsMultiplier)-Constants.safeArea!,
                    width: 60/2*Constants.guiPartsMultiplier,
                    height: 52/2*Constants.guiPartsMultiplier))
                self.view.addSubview(subBlueButton)
                subBlueButton.alpha = 1.0
                subBlueButton.backgroundColor = UIColor.blue
            }
    
            //down bar
            let bar = UIImageView.init(frame: CGRect(
                x:0,
                y: self.view.frame.size.height-50,
                width: self.view.frame.size.width,
                height: 50))
            bar.alpha = 0.3
            bar.backgroundColor = UIColor.blue
            self.view.addSubview(bar)
    }
    

    更新2

    assets

    更新3 考虑到安全区域,它在iPhoneX上看起来像这样,与iPhone6S上的完全不同。。。。

    iPhone 6s

    iPhone X

    2 回复  |  直到 8 年前
        2
  •  1
  •   Naresh    8 年前

    请点击此链接 https://developer.apple.com/design/human-interface-guidelines/ios/icons-and-images/image-size-and-resolution/

    在Xcode中选择资产文件夹-->在底部单击+符号-->选择新图像集-->设置名称-->现在拖放1x、2x和3x大小的图像。请参见此图像尺寸说明 What should image sizes be at @1x, @2x and @3x in Xcode?

    iPhone X、iPhone 8 Plus、iPhone 7 Plus和iPhone 6s Plus@3x

    所有其他高分辨率iOS设备@2x

    enter image description here

    新建图像集

    enter image description here

    在这里你需要设置你的图像名称和拖放图像