MyLayout框架使用

框架: https://github.com/youngsoft/MyLinearLayout
pod 'MyLayout'
MyLinearLayout 布局
UILabel *lable = [UILabel new];

myTop         /// 上边间距
myLeading  /// 左边边距
myTrailing  /// 右边边距
例如: 
     lable.myTop = 10; 
     lable.myLeading = 10; 
     lable.myLeading = 10;

/// 布局尺寸
myWidth
myHeight
mySize
例如: 
     lable.myWidth = 200; 
     lable.myHeight = 100; 
     lable.mySize = CGSizeMake(200, 100);

/// 自动计算高度
myHeight = MyLayoutSize.wrap;
例如: 
     lable.myHeight = MyLayoutSize.wrap;

/// 控件(水平)居中,(垂直)居中
myCenterX = 0;  myCenterY = 0;
例如: 
    lable.myTop = 10;
    lable.myCenterX = 0;
    lable.mySize = CGSizeMake(200, 100);  
待认证
rootLayout.widthSize.equalTo(scrollView.widthSize);
rootLayout.heightSize.equalTo(scrollView.heightSize).min(568 - 64);
待认证2 LLTest2ViewController
MyLinearLayout *contentLayout = [MyLinearLayout linearLayoutWithOrientation:MyOrientation_Vert];
    contentLayout.padding = UIEdgeInsetsMake(10, 10, 10, 10); //设置布局内的子视图离自己的边距.
    contentLayout.myHorzMargin = 0;                          //同时指定左右边距为0表示宽度和父视图一样宽
    contentLayout.heightSize.lBound(scrollView.heightSize, 10, 1); //高度虽然是自适应的。但是最小的高度不能低于父视图的高度加10.
    [scrollView addSubview:contentLayout];
待优化 LLTest2ViewController
布局: MyOrientation_Horz 中
UIImageView *headImageView;
headImageView.myCenterY = 0;  /// y轴垂直居中

MyLinearLayout *ageSelectLayout = [MyLinearLayout linearLayoutWithOrientation:MyOrientation_Horz];
for (int i = 0; i < 3; i++) {
  UILabel *ageLabel = [UILabel new];
  ageLabel.weight = 1.0;   //这里面每个子视图的宽度都是比重为1,最终的宽度是均分父视图的宽度
  [ageSelectLayout addSubview:ageLabel];
}

动画刷新布局
MyLinearLayout *contentLayout = [MyLinearLayout linearLayoutWithOrientation:MyOrientation_Vert];
[contentLayout layoutAnimationWithDuration:0.3];

布局 商品筛选

    MyFrameLayout *frameLayout = [MyFrameLayout new];
    frameLayout.backgroundColor = [UIColor redColor];
    frameLayout.myHorzMargin = 0;
    frameLayout.myVertMargin = 0;
    frameLayout.topPos.equalTo(self.topLayoutGuide).offset(10);  //顶部边距设置为10。
    [self.view addSubview:frameLayout];
线性水平居中
    MyLinearLayout *layout = [[MyLinearLayout alloc] initWithOrientation:MyOrientation_Horz];
    layout.gravity = MyGravity_Horz_Center;
    layout.backgroundColor = [UIColor grayColor];
    layout.topPos.equalTo(self.topLayoutGuide).offset(10);
    layout.myHorzMargin = 0;
    layout.myHeight = MyLayoutSize.wrap;
    [self.view addSubview:layout];
    
    UIView *red = [UIView new];
    red.backgroundColor = [UIColor redColor];
    red.myWidth = 100;
    red.myHeight = 50;
    [layout addSubview:red];
    
    UIView *blue = [UIView new];
    blue.backgroundColor = [UIColor blueColor];
    blue.myWidth = 100;
    blue.myHeight = 50;
    [layout addSubview:blue];
宽度写法等价
    UILabel *v1 ;
    v1.numberOfLines = 3;
    v1.topPos.equalTo(self.topLayoutGuide).offset(10);
    v1.myLeading = v1.myTrailing = 0; //宽度和父视图相等,等价v1.widthSize.equalTo(rootLayout.widthSize);
v2.widthSize.equalTo(rootLayout.widthSize).multiply(0.8);  //子视图的宽度是父视图宽度的0.8
Label最大宽度
MyLinearLayout *rootLayout = [MyLinearLayout linearLayoutWithOrientation:MyOrientation_Vert];
UILabel *userInfoLabel;
userInfoLabel.widthSize.uBound(rootLayout.widthSize, 0, 2);  //最大的宽度和父视图相等,这里第二个参数是第一个值的增量,第三个参数是第一个值的倍数
边距 -- 不能小于,不能超过
MyLinearLayout *rootLayout = [MyLinearLayout linearLayoutWithOrientation:MyOrientation_Vert];
 UILabel *userDescLabel;
userDescLabel.leadingPos.equalTo(@0.05).min(17).max(19); /// 距离父视图左边为布局视图宽度的5%,但是最小不能小于17,最大不能超过19。
高度 -- 不能小于,不能超过
MyLinearLayout *rootLayout = [MyLinearLayout linearLayoutWithOrientation:MyOrientation_Vert];
UITextView *textView;
textView.heightSize.equalTo(@(MyLayoutSize.wrap)).max(300).min(60); /// //虽然高度自适应,但是仍然不能超过300的高度以及不能小于60的高度。

标签流

UIScrollView *scrollView = [UIScrollView new];
scrollView.backgroundColor = [UIColor whiteColor];
self.view = scrollView;

MyLinearLayout *rootLayout = [MyLinearLayout linearLayoutWithOrientation:MyOrientation_Vert];
rootLayout.myHorzMargin = 0;
rootLayout.gravity = MyGravity_Horz_Fill;
rootLayout.heightSize.lBound(scrollView.heightSize, 0, 1);
[scrollView addSubview:rootLayout];

MyFlowLayout *contentLayout = [MyFlowLayout flowLayoutWithOrientation:MyOrientation_Vert arrangedCount:0];
contentLayout.myHeight = MyLayoutSize.wrap;
contentLayout.padding = UIEdgeInsetsMake(5, 5, 5, 5);
contentLayout.subviewSpace = 5;
contentLayout.backgroundColor = [CFTool color:0];
[rootLayout addSubview:contentLayout];

contentLayout.autoArrange = YES;  //自动排列,布局视图会根据里面子视图的尺寸进行智能的排列。
contentLayout.gravity = MyGravity_Horz_Fill;  //对于内容填充流式布局来说会拉升所有子视图的尺寸,以便铺满整个布局视图。
    
//添加N个长短不一的子视图。
for (int i = 0; i < 15; i++)
{
    UILabel *label = [UILabel new];
    label.text = [NSString stringWithFormat:@"%02d",i];
    label.adjustsFontSizeToFitWidth = YES;
    label.textAlignment = NSTextAlignmentCenter;
    label.myWidth = random() % 150 + 20; //最宽170,最小20.
    label.myHeight = 30;
    label.backgroundColor = [UIColor colorWithRed:random()%256 / 255.0 green:random()%256 / 255.0 blue:random()%256 / 255.0 alpha:1];
    [contentLayout addSubview:label];
}
E998B177-521D-46AC-9997-3EC7AED597C8.png

流式布局,平均个数

    MyFlowLayout *contentLayout = [MyFlowLayout flowLayoutWithOrientation:MyOrientation_Vert arrangedCount:3];
    contentLayout.backgroundColor = [UIColor redColor];
    contentLayout.myHorzMargin = 0;
    contentLayout.myVertMargin = 0;
    contentLayout.gravity = MyGravity_Horz_Fill | MyGravity_Vert_Fill;
    contentLayout.padding = UIEdgeInsetsMake(0, 0, 0, 0);
    contentLayout.subviewVSpace = 0; //设置流式布局里面子视图之间的垂直间距。
    [vessel addSubview:contentLayout];
    
    for (NSInteger i = 0; i < 3; i++) {
        UIView *jj = [UIView new];
        jj.backgroundColor = [UIColor jk_randomColor];
//        jj.myVertMargin = 0;
//        jj.myWidth = 20;
        [contentLayout addSubview:jj];
    }
BCBB7650-CFE7-4AB8-B438-90BD7086171E.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 159,219评论 4 362
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,363评论 1 293
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,933评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,020评论 0 206
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,400评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,640评论 1 219
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,896评论 2 313
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,597评论 0 199
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,327评论 1 244
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,581评论 2 246
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,072评论 1 261
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,399评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,054评论 3 236
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,083评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,849评论 0 195
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,672评论 2 274
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,585评论 2 270

推荐阅读更多精彩内容