亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫(kù)
最近訪問(wèn)板塊 發(fā)新帖
查看: 1612 | 回復(fù): 0
打印 上一主題 下一主題

[iOS] iOS xib 嵌套復(fù)用 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2015-07-10 15:20 |只看該作者 |倒序?yàn)g覽
國(guó)內(nèi)對(duì)于 xib嵌套或xib復(fù)用的帖子或有效代碼很少,但是我仔細(xì)查閱了各種資料,最終還是提煉出了一種簡(jiǎn)單可行的用于實(shí)現(xiàn) xib 的方法與具體實(shí)現(xiàn). 思路見(jiàn)代碼注釋. 靈感來(lái)源于:  http://www.maytro.com/2014/04/27 ... nd-auto-layout.html 這個(gè)帖子.但是它給的代碼,是有問(wèn)題的,并不能真正實(shí)現(xiàn)復(fù)用;但思路很有啟發(fā)性.
示例工程,可直接運(yùn)行!

用于編寫可嵌套的 xib 組件.
  1. /**
  2. *  可復(fù)用組件.用于編寫可嵌套的 xib 組件.
  3. *  
  4. *  適用場(chǎng)景: 需要靜態(tài)確定布局的頁(yè)面內(nèi)的UI元素的復(fù)用性問(wèn)題.
  5. *  使用方法: 在xib或storyboard中,將某一用于占位的view的 custom class 設(shè)為對(duì)一個(gè)的 component, 則初始化時(shí),會(huì)自動(dòng)使用此component同名的xib文件中的內(nèi)容去替換對(duì)應(yīng)位置.
  6. *  注意: 對(duì)于可動(dòng)態(tài)確定布局的部分,如tableView中的cell,直接自行從xib初始化即可,不必繼承于 MCComponent.
  7. */
  8. @interface MCComponent : UIView

  9. @end
復(fù)制代碼
核心實(shí)現(xiàn)文件
  1. #import "MCComponent.h"

  2. @implementation MCComponent

  3. - (instancetype)initWithCoder:(NSCoder *)aDecoder
  4. {
  5.     self = [super initWithCoder:aDecoder];
  6.      
  7.     if (nil != self) {
  8.         UIView * contentView = [[[NSBundle mainBundle] loadNibNamed: NSStringFromClass([self class]) owner:self options:nil] firstObject];
  9.          
  10.         contentView.translatesAutoresizingMaskIntoConstraints = NO;
  11.         self.translatesAutoresizingMaskIntoConstraints = NO;
  12.          
  13.         [self addSubview: contentView];
  14.          
  15.         [self addConstraint: [NSLayoutConstraint constraintWithItem: contentView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem: self attribute:NSLayoutAttributeLeft multiplier: 1.0 constant: 0]];
  16.         [self addConstraint: [NSLayoutConstraint constraintWithItem: contentView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem: self attribute:NSLayoutAttributeRight multiplier: 1.0 constant: 0]];
  17.         [self addConstraint: [NSLayoutConstraint constraintWithItem: contentView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem: self attribute:NSLayoutAttributeTop multiplier: 1.0 constant: 0]];
  18.         [self addConstraint: [NSLayoutConstraint constraintWithItem: contentView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem: self attribute:NSLayoutAttributeBottom multiplier: 1.0 constant: 0]];
  19.     }
  20.      
  21.     return self;
  22. }

  23. /*
  24. // Only override drawRect: if you perform custom drawing.
  25. // An empty implementation adversely affects performance during animation.
  26. - (void)drawRect:(CGRect)rect {
  27.     // Drawing code
  28. }
  29. */

  30. @end
復(fù)制代碼
您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國(guó)互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過(guò)ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP