• Stars
    star
    251
  • Rank 161,862 (Top 4 %)
  • Language
    Objective-C
  • License
    MIT License
  • Created over 8 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Flexbox in Objective-C, using Facebook's css-layout.

MLLayout

License MIT  CocoaPods  CocoaPods  Build Status 

Flexbox in Objective-C, using Facebook's css-layout.

Inspired by React Native.

  • Flexbox is the best way to layout in mobile platform. So many popular libraries use it, eg: componentkit, AsyncDisplayKit, React Native, weex and so on.
  • React Native,weex and MLLayout are based on the C implementation of facebook/css-layout.
  • Some code references from React Native, eg: snapping to the pixel grid(No misaligned images to improve drawing performance]).
  • MLLayout also can be used for layout calculation only. Every layout associated with a view usually, the calculation updates frames of layouts. You can use the frames directly or change them. with your mind.
  • MLTagViewFrameRecord can preserve current topology of layouts or views. A prerequisite is that each has a valid tag.
  • Using MLTagViewFrameRecord related TableView and TableViewCell can ensure the layout calculation for one row would not be excuted twice unless reloading it explicitly. The feather can improve scrolling performance greatly.

FlexBox Guide: https://css-tricks.com/snippets/css/a-guide-to-flexbox/

##中文介绍

  • Flexbox是现今移动端最优的布局方式,像componentkit, AsyncDisplayKit, React Native, weex等等优秀的开源库都在使用此种布局方式。
  • React Nativeweex以及MLLayout都一样是基于facebook开源facebook/css-layout的c实现。
  • MLLayout的一些代码实现是借鉴于React Native,例如布局计算结果进行默认像素对齐,提升渲染性能。
  • MLLayout也可以只作为以语义化的形式快速计算布局的工具来用,最终计算出的结果使用与否,随心而定。
  • MLTagViewFrameRecord可以记录当前的布局结构,但是前提是需要缓存frame的view需要有独特的tag,这样后续才能将记录应用到对应的view上。
  • MLTagViewFrameRecord相关的TableView和TableViewCell呢,提供了自动缓存cell布局(当然顺带也有高度啦)的实现,这样的话能保证同一行的布局只会计算一次,除非显式reload。这个能大大的提高列表的滚动性能。

花丁点时间学习一下就会发现使用此库写布局代码量很少,并且会让以后维护成本特别的低,代码结构也利索,甚至几乎天生就适配了横竖屏。大言不惭的说,OC原生下最爽的布局库即为本库,不过暂时demo里没有把各个点说全,细节有点多,随着各位兴趣度我再努力添加吧。

FlexBox教程: http://www.ruanyifeng.com/blog/2015/07/flex-grammar.html?utm_source=tuicool

Usage

Simple demo below:

SimpleViewController


MLLayout *bkgViewLayout = [MLLayout layoutWithTagView:_bkgView block:^(MLLayout * _Nonnull l) {
        l.marginLeft = l.marginRight = 10.0f;
        //test for round pixel
        l.padding = UIEdgeInsetsMake(10.34f, 15.37f, 10.5608f, 15.3567f);
        
        l.flexDirection = MLLayoutFlexDirectionColumn;
        l.alignItems = MLLayoutAlignmentCenter;
        l.alignSelf = MLLayoutAlignmentCenter;
        l.sublayouts = @[
                         [MLLayout layoutWithTagView:_firstLabel block:nil],
                         [MLLayout layoutWithTagView:_secondLabel block:^(MLLayout * _Nonnull l) {
                             l.marginTop = 10.0f; //space
                             l.flex = -1;
                         }],
                         ];
    }];
    
    _layout = [MLLayout layoutWithTagView:self.view block:^(MLLayout * _Nonnull l) {
        l.flexDirection = MLLayoutFlexDirectionColumn;
        l.justifyContent = MLLayoutJustifyContentCenter;
        l.alignItems = MLLayoutAlignmentCenter;
        l.sublayouts = @[
                         [MLLayout layoutWithTagView:nil block:^(MLLayout * _Nonnull l) {
                             //test MLLayoutPositionAbsolute
                             l.position = MLLayoutPositionAbsolute;
                             l.bottom = 20.0f;
                             l.right = 20.0;
                             
                             l.flexDirection = MLLayoutFlexDirectionColumn;
                             l.sublayouts = @[
                                              [MLLayout layoutWithTagView:_button block:nil],
                                              [MLLayout layoutWithTagView:displaySwitchButton block:^(MLLayout * _Nonnull l) {
                                                  l.marginTop = 10.0f;
                                              }]
                                              ];
                         }],
                         [MLLayout layoutWithTagView:_imageView block:^(MLLayout * _Nonnull l) {
                             //test MLLayoutPositionRelative
                             l.position = MLLayoutPositionRelative;
                             l.bottom = 10.0f;
                         }],
                         bkgViewLayout
                         ];
    }];
    

TweetListViewController

The demo uses MLLayout to layout subviews of cells and MLTagViewFrameRecord to preserve all layout result. Ensure that the layout calculation for one row would not be excuted twice unless reloading it explicitly. The feature can improve scrolling performance greatly.

Installation

CocoaPods

  1. Add pod 'MLLayout' to your Podfile.
  2. Run pod install or pod update.
  3. Import <MLLayout/MLLayout.h>.

Requirements

This library requires iOS 7.0+ and Xcode 7.0+.

License

MLLayout is provided under the MIT license. See LICENSE file for details.

More Repositories

1

MLEmojiLabel

Automatic URL recognition and custom expression like wechat
Objective-C
803
star
2

MLLabel

UILabel replacement with TextKit. Support link and expression.
Objective-C
724
star
3

MLTransition

iOS7+, pop ViewController with pan gesture from middle or edge of screen.
Objective-C
452
star
4

MLAutoReplace

Xcode plugin which help you write code faster.
Objective-C
232
star
5

MLInputDodger

The best view dodger for inputting.
Objective-C
203
star
6

MLAudioRecorder

练手之作,实现不怎么样,可能存在问题,也不继续维护,所以注意仅供参考学习。
Objective-C
181
star
7

MLNavigationBarTransition

Advanced navigation bar transition based on official push-pop transition
Objective-C
78
star
8

MLPresentController

Present ViewController with custom animator. support interactiving with UIPanGestureRecognizer
Objective-C
55
star
9

MLMultiSelectViewController

multi select contact like wechat group
Objective-C
43
star
10

MLImageCrop

image crop ,custom ratio , can rotate - 图片截取,可以自定义截取比例,支持旋转
Objective-C
31
star
11

MLIgnoreTransparentButton

a button can ignore touch of transparent area and a uiview category can auto set mask with image.
Objective-C
9
star
12

MLAudio

MLAudio - 暂时请勿关注,方便自己使用的玩意。
Objective-C
7
star
13

Arm64InspectiveC

Based on InspectiveC. Print on console. No theos/tweak/cycript depend.
Objective-C++
4
star
14

MLActivityView

ActivityView Like WeChat - 类似微信的ActivityViewController
Objective-C
4
star
15

jsoniterpb

Replacement of Protojson over Jsoniter Extension
Go
3
star
16

MLKit

自用,暂请勿关注
Objective-C
3
star
17

gopit

golang大坑集锦
Go
3
star
18

MLActionSheet

ActionSheet - 类似Instagram的
Objective-C
2
star
19

MLDataSyncPool

simple data sync pool
Objective-C
2
star
20

MLRefreshControl

Refresh control for UIScrollView
Objective-C
2
star
21

zlib

zlib cgo wrapper
Go
1
star
22

MLAlipaySDK

方便使用罢了 请勿关注~~~!!!!!
Objective-C
1
star
23

MLSmoothCorner

smooth using for corner of UIView
Objective-C
1
star
24

MLHttpDNS

Objective-C
1
star