Git Product home page Git Product logo

getdeviceinfodemo's Introduction

GetDeviceInfoDemo

获取设备相关信息,如屏幕宽高、设备型号、系统版本

介绍

本工程获取三种常用的设备信息:

  • 获取屏幕的宽高。用于在设置控件位置的时候计算相对屏幕的距离
  • 获取设备的型号。5s和6+的屏幕大小相差很远,相应的控件位置、大小都需要做出调整,不然就会出现在6+上显得很空旷或者在5s上显示不全的问题。
  • 获取系统版本。不同的系统版本有着不同的特性,举个栗子,iOS 9以下的版本就没有Live Photo;再举个栗子,iOS 7以上的系统版本往往需要调整一下边界

方法

以下方法均使用pch宏文件来设置,便于全局调用

  • 获取屏幕的宽高
// 设备宽度  
#define SCREENWIDTH       [UIScreen mainScreen].bounds.size.width 
  
// 设备高度  
#define SCREENHEIGHT      [UIScreen mainScreen].bounds.size.height
  • 获取设备的型号
// 根据屏幕分辨率判断设备,是则返回YES,不是返回NO  
#define isiPhone5or5sor5c ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)  
#define isiPhone6or6s ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size) : NO)  
#define isiPhone6plusor6splus ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2208), [[UIScreen mainScreen] currentMode].size) : NO) 

设备信息表格:

  • 获取系统版本
// 设备的系统版本  
#define SystemVersion ([[UIDevice currentDevice] systemVersion]) 

// 使用:
if ([SystemVersion floatValue] >= 7.0)  
{  
    ……  
}  

getdeviceinfodemo's People

Contributors

cloudox avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

yanglangfei

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.