Code Monkey home page Code Monkey logo

gjratioautolayout's Introduction

GJRatioAutoLayout

A scaled Autolayout framework by screen ratio.

一个根据屏幕比率进行缩放的AutoLayout库,iOS程序员经常会被UI虐待,要么是UI太水,不会根据iOS适配规则进行UI设计,要么是真的需要一些地方采用UI根据屏幕进行等比缩放,但程序员们大都中了Autolayout的毒,很难打破重新使用frame的心理障碍,痛不欲生;根据这种情况,我们开发了在Autolayout下,只需一个开关,即可让当前view进行等比缩放,不必放弃Autolayout,又完成了UI缩放任务。

此库由宜信·宜人贷-宜人贷理财GJ开源小组进行开发。

(作者英文过于low,请见谅)

Start

add Directory 'GJRatioAutoLayout', contain this files:

  • GJRatioAutoLayout
  • GJRatioAutoLayoutDefine
  • UILabel+GJRatioAutoLayout
  • UIView+GJRatioAutoLayout

you can use this code to set base screen:

[GJRatioAutoLayout startWithScreenSizeType:GJScreenSizeTypeiPhone4or5]; 

default is 320 width screen, if you don't do anything.

you can use Interface builder or Code to set scale start, ALRatio set On in IB and object's property of UIView aLRatio = YES.

- (void)createSomeViews {
    self.oneView.aLRatio = YES;
}

we support Masonry and PureLayout:

- (void)createSomeViews {
    UIImageView *codeImageView = [[UIImageView alloc]init];
    codeImageView.image = [UIImage imageNamed:@"icon"];
    codeImageView.aLRatio = YES;
    [self.view addSubview:codeImageView];
    [codeImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.equalTo(self.view).offset(50);
    }];
}

开始使用

添加文件夹'GJRatioAutoLayout'到项目中,包含如下文件:

  • GJRatioAutoLayout
  • GJRatioAutoLayoutDefine
  • UILabel+GJRatioAutoLayout
  • UIView+GJRatioAutoLayout

你可以使用这段代码来设置以哪个屏幕为基准:

[GJRatioAutoLayout startWithScreenSizeType:GJScreenSizeTypeiPhone4or5]; 

如果你什么都不写,则默认以320屏幕宽度为基础。

你可以使用界面编辑器或者代码来启动等比缩放,在IB中得ALRatio属性设为On,或者将UIView的对象的属性aLRatio = YES来开启。

- (void)createSomeViews {
 self.oneView.aLRatio = YES;
}

我们也支持Masonry和PureLayout等第三方库:

- (void)createSomeViews {
    UIImageView *codeImageView = [[UIImageView alloc]init];
    codeImageView.image = [UIImage imageNamed:@"icon"];
    codeImageView.aLRatio = YES;
    [self.view addSubview:codeImageView];
    [codeImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.equalTo(self.view).offset(50);
    }];
}

注意!

UIImageView和UILabel如果不设置宽高约束,会根据内容及字号进行拉伸。

gjratioautolayout's People

Contributors

wangyutao0424 avatar

Watchers

john.young 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.