GithubHelp home page GithubHelp logo

ruler's Introduction

Ruler

In some cases, we need to distinguish between different devices to set UI, but Adaptive Layout can not do that. So, there is a Ruler.

Requirements

Swift 4, iOS 8.0

(Swift 3, use version 1.0.1)

Example

If we only consider iPhone's width, iPhone 5 has the same width of iPhone 4s, iPhone 6 has a bigger width, iPhone 6 Plus' width even bigger than iPhone 6, and iPhone X's width is the biggest. Only four widths.

But if we consider full screen size of iPhone, there are five models, because iPhone 5's height is different from iPhone 4s'.

If our app is universal, we need consider iPad, there are two models (in points).

So all we need consider five cases as follows:

enum Ruler<T> {
    case iPhoneHorizontal(T, T, T)
    case iPhoneVertical(T, T, T, T, T)
    case iPad(T, T)
    case universalHorizontal(T, T, T, T, T)
    case universalVertical(T, T, T, T, T, T, T)
}

In real world (thanks generics, Ruler can match anything for different sizes of iOS devices):

import Ruler
// size, off course

let width = Ruler.iPhoneHorizontal(10, 20, 30).value
let height = Ruler.iPhoneVertical(5, 10, 20, 30, 40).value

// or color

colorView.backgroundColor = Ruler.universalVertical(UIColor.black, UIColor.red, UIColor.blue, UIColor.green, UIColor.yellow, UIColor.purple, UIColor.cyan).value

// even closures

typealias Greeting = () -> Void

let greeting: Greeting = Ruler.universalVertical(
{ print("Hello!") },
{ print("Hi!") },
{ print("How are you!") },
{ print("How do you do!") },
{ print("好久不见!") },
{ print("你好!") },
{ print("很高兴见到你!") }).value

greeting()

// ...

Special offer

Detect if this device is an iPhone X:

if ScreenModel.isPhoneX {
    print("It's an iPhone X. You're rich!")
}

Installation

Feel free to drag Ruler.swift to your iOS Project. But it's recommended to use Carthage (or CocoaPods).

Carthage

github "nixzhu/Ruler"

CocoaPods

pod 'Ruler'

Contact

NIX @nixzhu

License

Ruler is available under the MIT license. See the LICENSE file for more info.

ruler's People

Contributors

lanfordcai avatar nixzhu avatar rayps avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

ruler's Issues

在iPhone6 缩放模式下的问题

iPhone6 设置-显示与亮度-显示模式-放大,这时UIScreen.main().bounds.size.width = 320,而nativeBounds不能区分这种情况,还会按iPhone6的尺寸显示。而实际上这种情况下应该按iPhone5的尺寸显示。

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.