Xib的简单使用

一、简单介绍

xib和storyboard的比较,一个轻量级一个重量级。

共同点:

都用来描述软件界面

都用Interface Builder工具来编辑

不同点:

Xib是轻量级的,用来描述局部的UI界面

Storyboard是重量级的,用来描述整个软件的多个界面,并且能展示多个界面之间的跳转关系

二、简单使用

说实话,经常逛大牛的博客的确是一件伤脑经的事情(我先申明人家写的非常好,只是长篇大论对于我急忙找出自己满意的地方的过程是一件痛苦的过程),我不知道大家怎么想,有的东西有时候很简单,不需要细说的时候,有时候说的太细了反而感觉啰嗦。哈哈!废话少说,至于Xib怎么建立,怎么命名,我就不多说了,我觉得这个没啥技术水平。下面仅仅将写的很菜的Demo展示下!希望大家不要打我啊!哈哈!

三、示例代码

--tableViewCell关联Xib的代码

--下面是ImageView(美女图片)、describtion(美女一枚,求带走)和name(Label)的的Xib布局。

.m控制器里的代码实现

//Created bysyc on 16/3/25.

//Copyright © 2016年YS. All rights reserved.


#import"TableViewController.h"

#import"TableViewCell.h"

@interfaceTableViewController()

@property(strong,nonatomic)IBOutletUITableView*tableView;

@end

@implementationTableViewController

- (void)viewDidLoad {

[superviewDidLoad];

self.tableView.rowHeight=100;

}

- (void)didReceiveMemoryWarning {

[superdidReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

#pragma mark - table view dataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView*)tableView {

   return  1;

}

- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section {

   return   4;

}

- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath {

TableViewCell*cell = [tableViewdequeueReusableCellWithIdentifier:@"cell"];

if(cell ==nil) {

NSArray*nibs =[[NSBundlemainBundle]loadNibNamed:@"TableViewController"owner:niloptions:nil];

cell = [nibslastObject];

cell.name.text=@"小明";

}

cell.backgroundColor= [UIColorclearColor];

returncell;

}

#pragma mark - table view delegate

- (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath {

//kTipAlert(@"<%ld> selected...", indexPath.row);

}

以下是截图代码(功能和上面一样


就废话这么多了吧!哈哈!感觉对自己用用的可以看看哦!咋们下次不见不散!(废话!下次必须见的!是吧?Smile)

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

友情链接更多精彩内容