iOS 開發 ZFUI framework控制項,使布局更簡單

來源:互聯網
上載者:User

標籤:

來自:http://www.jianshu.com/p/bcf86b170d9c

前言

      為什麼會寫這個?因為在iOS開發中,介面的布局一直沒有Android布局有那麼多的方法和優勢,我個人開發都是純程式碼,Masonry這個架構我在開發中也是不用的,一個是代碼布局的時候,代碼量比較多,另外好像在iOS10 布局有問題,網上也有些解決的方法了。

所以就想能自訂一些UI控制項,使布局更加簡單

實現思路

可以像Android的wrap_content一樣,是UILabel 可以根據內容來展示控制項的寬高

目前提供ZFUI framework裡只提供了UILabel和UIButton的方法

它們都繼承對應父類,然後重寫裡父類的方法,讓控制項使用更加簡單和方便

實現方法

直接上代碼,Demo和framework可以去github上下載

https://github.com/joshuaGeng/ZFUI-Framework

首先把ZFUI.framework 添加到項目裡

調用的方法

#import <ZFUI/ZFUI.h>

// 建立一個Label的方法

ZFUILabel *label = [[ZFUILabel alloc] init];

label.numberOfLines = 0;

label.backgroundColor = [UIColor greenColor];

[label setLabelText:@"HelloWorld" andWithFrame:CGRectMake(100, 70, 0, 0)];

//label.isCanCopy = YES;

//label.titleCopy = @"Copy";

//設定不同顏色

[label setAttributeColorWithAllStr:label.text andAllColor:[UIColor redColor] andWithDiffStr:@"World" andDiffColor:[UIColor blackColor]];

[self.view addSubview:label];

// button

ZFUIButton *button = [[ZFUIButton alloc] initWithFrame:CGRectMake(100, 120, 120, 60)];

[button setImage:[UIImage imageNamed:@"img"] forState:UIControlStateNormal];

[button setTitle:@"Button" forState:UIControlStateNormal];

button.backgroundColor = [UIColor orangeColor];

button.btnImgRect = CGRectMake(10, 20, 22, 21);

button.btnTitleRect = CGRectMake(50, 20, 120, 30);

[self.view addSubview:button];

目前提供ZFUI framework裡只提供了UILabel和UIButton的方法,後續還會繼續更新,有需要的可以下載,Demo裡的注釋也很很詳細。

iOS 開發 ZFUI framework控制項,使布局更簡單

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.