Coder Social home page Coder Social logo

taroyuyu / iblayoutconstraint Goto Github PK

View Code? Open in Web Editor NEW

This project forked from maksimkurpa/iblayoutconstraint

0.0 0.0 0.0 903 KB

๐Ÿ“ Configure constraints for each device in Interface Builder with IBLayoutConstraint.

License: MIT License

Ruby 3.50% Swift 96.50%

iblayoutconstraint's Introduction

IBLayoutConstraint

๐Ÿ“ Configure constraints for each device in Interface Builder with IBLayoutConstraint.

Requirements

IBLayoutConstraint is written in Swift 5.0 and is available on iOS/Mac Catalyst 11.0 or higher.

Installation

Dependency Managers

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To integrate IBLayoutConstraint into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://cdn.cocoapods.org/'
platform :ios, '11.0'

pod 'IBLayoutConstraint'

Then, run the following command:

$ pod install

Introduction

The main thought of this framework is convinient way to configure constraint for each device in Interface Builder. Sometimes we need to change constant/multiplier value for NSLayoutConstraint only for specific device, for example, for iPhone 5s (4"). If this UIView with layout has special constraint for one device, we should do:

  1. inheritance from UIView
  2. add outlet to this view @IBOutlet weak private var someConstraint: NSLayoutConstraint!
  3. add some code to change constraint's value for specific device
if UIDevice.current.isIPhone5() {
     someConstraint.constant = 290
}

IBLayoutConstraint will takes responsibility for this cases.

How to use

(!) Notice: This approach isn't quite obvious, and you should point out it in documentation of your project.
  1. Find constraint for configuration in Interface Builder View in Xcode.

  2. Go to Indentity Inspector for this constraint in right-side panel.

  3. Change Class NSLayoutConstraint to IBLayoutConstraint

    If you want to specify multiplier value or constraintand multiplier toghether, you should use IBMultiplierLayoutConstraint.

  4. Go to Attributes Inspector for this constraint in right-side panel. You'll see:

IBLayoutConstraint

IBLayoutConstraint

IBMultiplierLayoutConstraint

IBLayoutConstraint
  1. Find the screen size in inches that matches your need. You'll see two textfields:

    Width - value for landscape mode

    Height - value for portrait mode

    Fill the text fields. The necessary value will be applied after initialization and will change accordingly after device rotation.

Note: You don't need specify values for all sizes,but you need specify values for 'width' and 'height' in one line - it is required (even if you don't support rotation). If values don't specified for some size - IBLayoutConstraint will work as NSLayoutConstraint.

Contributing

Issues and pull requests are welcome!

Author

Maksim Kurpa - @maksim_kurpa

License

This code is distributed under the terms and conditions of the MIT license.

iblayoutconstraint's People

Contributors

maksimkurpa avatar

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.