UIAdapter - An elegant solution to the iOS screen adaptation problem

Overview

UIAdapter - An elegant solution to the iOS screen adaptation problem

License  Swift  Platform  Swift Package Manager  Carthage  Cocoapods

🇨🇳 天朝子民

Features

  • Numerical type fast conversion
  • Storyboard equal scale adaptation
  • Xib equal scale adaptation
  • Custom calculation processing
  • Quick match for each screen size type

Installation

CocoaPods - Podfile

pod 'UIAdapter'

Carthage - Cartfile

github "lixiang1994/UIAdapter"

Swift Package Manager for Apple platforms

Select Xcode menu File > Swift Packages > Add Package Dependency and enter repository URL with GUI.

Repository: https://github.com/lixiang1994/UIAdapter

Swift Package Manager

Add the following to the dependencies of your Package.swift:

.package(url: "https://github.com/lixiang1994/UIAdapter.git", from: "version")

Usage

First make sure to import the framework:

import UIAdapter

Here are some usage examples. All devices are also available as simulators:

Zoom

AutoLayout (SnapKit):

private func setupLayout() {
    cardView.snp.makeConstraints { (make) in
	make.top.equalTo(16.zoom())
	make.left.right.equalToSuperview().inset(15.zoom())
	make.bottom.equalTo(-26.zoom())
    }
	
    lineView.snp.makeConstraints { (make) in
	make.left.right.equalToSuperview().inset(15.zoom())
	make.top.equalTo(titleLabel.snp.bottom)
	make.height.equalTo(1)
    }
        
    titleLabel.snp.makeConstraints { (make) in
        make.top.equalToSuperview()
        make.left.equalTo(15.zoom())
        make.height.equalTo(48.zoom())
    }
        
    stateLabel.snp.makeConstraints { (make) in
        make.top.equalTo(lineView).offset(10.zoom())
        make.left.equalTo(15.zoom())
        make.height.equalTo(15.zoom())
    }
}

Property (Then):

private lazy var cardView = UIView().then {
    $0.cornerRadius = 6.zoom()
    $0.backgroundColor = .white
}

private lazy var lineView = UIView().then {
    $0.backgroundColor = .hex("000000", alpha: 0.05)
}

private lazy var titleLabel = UILabel().then {
    $0.textColor = .black
    $0.font = .systemFont(ofSize: 20.zoom(), weight: .medium)
}

private lazy var stateLabel = UILabel().then {
    $0.textColor = .gray
    $0.font = .systemFont(ofSize: 12.zoom(), weight: .medium)
}

Storyboard / Xib:

Constraint UILabel Font

Screen

e.g.

// default other screen numberOfLines = 0
// 3.5 inches screen numberOfLines = 1
// 4.0 inches screen numberOfLines = 2
label.numberOfLines = 0.screen.inch(._3_5, is: 1).inch(._4_0, is: 2).value
// default other screen numberOfLines = 0
// width 320 screen numberOfLines = 1
// width 375 inches screen numberOfLines = 2
label.numberOfLines = 0.screen.width(._320, is: 1).width(._375, is: 2).value
print("this is " +
    "default".screen
    .width(._320, is: "width 320")
    .width(._375, is: "width 375")
    .height(._844, is: "height 844")
    .height(._812, is: "height 812")
    .inch(._4_7, is: "4.7 inches")
    .inch(._5_8, is: "5.8 inches")
    .inch(._6_5, is: "6.5 inches")
    .level(.compact, is: "screen 3: 2")
    .level(.regular, is: "screen 16: 9")
    .level(.full, is: "screen 19.5: 9")
    .value
)

Screenshot

TikTok 1

TikTok 2

Contributing

If you have the need for a specific feature that you want implemented or if you experienced a bug, please open an issue. If you extended the functionality of UIAdapter yourself and want others to use it too, please submit a pull request.

License

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

相关文章 Inch

相关文章 Auto

相关文章 Auto


欢迎入群交流

QQ

You might also like...
Bar Button Item that can be moved anywhere in the screen, like Android's stickers button.
Bar Button Item that can be moved anywhere in the screen, like Android's stickers button.

FlowBarButtonItem Bar Button Item that can be moved anywhere in the screen, like Android's stickers button. [![CI Status](http://img.shields.io/travis

UIStackView replica for iOS 7.x and iOS 8.x
UIStackView replica for iOS 7.x and iOS 8.x

TZStackView A wonderful layout component called the UIStackView was introduced with iOS 9. With this component it is really easy to layout components

Super awesome Swift minion for Core Data (iOS, macOS, tvOS)

⚠️ Since this repository is going to be archived soon, I suggest migrating to NSPersistentContainer instead (available since iOS 10). For other conven

A custom stretchable header view for UIScrollView or any its subclasses with UIActivityIndicatorView and iPhone X safe area support for content reloading. Built for iOS 10 and later.

Arale A custom stretchable header view for UIScrollView or any its subclasses with UIActivityIndicatorView support for reloading your content. Built f

💾 A collection of classic-style UI components for iOS
💾 A collection of classic-style UI components for iOS

A collection of classic-style UI components for UIKit, influenced by Windows 95 Introduction This is a little exploration into applying '90s-era desig

A simple, customizable view for efficiently collecting country information in iOS apps.
A simple, customizable view for efficiently collecting country information in iOS apps.

CountryPickerView CountryPickerView is a simple, customizable view for selecting countries in iOS apps. You can clone/download the repository and run

A library to recreate the iOS Apple Music now playing transition
A library to recreate the iOS Apple Music now playing transition

DeckTransition DeckTransition is an attempt to recreate the card-like transition found in the iOS 10 Apple Music and iMessage apps. Hereʼs a GIF showi

A message bar for iOS written in Swift.
A message bar for iOS written in Swift.

Dodo, a message bar for iOS / Swift This is a UI widget for showing text messages in iOS apps. It is useful for showing short messages to the user, so

Protocol oriented, type safe, scalable design system foundation swift framework for iOS.
Protocol oriented, type safe, scalable design system foundation swift framework for iOS.

Doric: Design System Foundation Design System foundation written in Swift. Protocol oriented, type safe, scalable framework for iOS. Features Requirem

Releases(1.2.0)
Owner
LEE
iOS Developer
LEE
📖 A lightweight, paging view solution for SwiftUI

Getting Started | Customization | Installation Getting Started Basic usage Using Pages is as easy as: import Pages struct WelcomeView: View { @S

Nacho Navarro 411 Dec 29, 2022
Newly is a drop in solution to add Twitter/Facebook/Linkedin style, new updates/tweets/posts available button

Newly is a drop in solution to add Twitter/Facebook/Linkedin style, new updates/tweets/posts available button. It can be used to notify user about new content availability and can other actions can be triggers using its delegate method.

Dhiraj Rajendra Jadhao 197 Sep 22, 2022
A simple and elegant UIKit for iOS.

HamsterUIKit A simple and elegant UIKit(Chart) for iOS, written in Swift. ?? Curve and bar Charts. ?? Protocols are designed based on UIKit(UITableVie

Howard Wang 30 Oct 2, 2022
☠️ An elegant way to show users that something is happening and also prepare them to which contents they are awaiting

Features • Guides • Installation • Usage • Miscellaneous • Contributing ?? README is available in other languages: ???? . ???? . ???? . ???? . ???? To

Juanpe Catalán 11.7k Jan 6, 2023
🚀 Elegant Pager View fully written in pure SwiftUI.

PagerTabStripView Made with ❤️ by Xmartlabs team. XLPagerTabStrip for SwiftUI! Introduction PagerTabStripView is the first pager view built in pure Sw

xmartlabs 482 Jan 9, 2023
Creating a simple selectable tag view in SwiftUI is quite a challenge. here is a simple & elegant example of it.

SwiftUI TagView Creating a simple selectable tag view in SwiftUI is quite a challenge. here is a simple & elegant example of it. Usage: Just copy the

Ahmadreza 16 Dec 28, 2022
ElongationPreview is an elegant UI push-pop style view controller

ElongationPreview is an elegant UI push-pop style view controller

Ramotion 886 Dec 19, 2022
Elegant Apply Style by Swift Method Chain.🌙

ApplyStyleKit ApplyStyleKit is a library that applies styles to UIKit using Swifty Method Chain. Normally, when applying styles to UIView etc.,it is n

shindyu 203 Nov 22, 2022
BulletinBoard is an iOS library that generates and manages contextual cards displayed at the bottom of the screen

BulletinBoard is an iOS library that generates and manages contextual cards displayed at the bottom of the screen. It is especially well

Alexis (Aubry) Akers 5.3k Jan 2, 2023
DesafioMobile2You - This project consists of creating a replica of a TodoMovies screen

DesafioMobile2You Swift IOS Este projeto consiste na criação da réplica de uma t

Leonardo P M 0 Feb 3, 2022