10张图告诉你Storyboard的强大!

Storyboard对TableView的强力支持

  1. 为tableview添加headview,footview
10张图告诉你Storyboard的强大!_第1张图片
record1.gif

10张图告诉你Storyboard的强大!_第2张图片
运行图
  1. Storyboard直接关联cell

创建cell文件,并与storyboard视图cell关联,并设置复用标识


record2.gif

关联属性


record3.gif

10张图告诉你Storyboard的强大!_第3张图片
Simulator Screen Shot 2016年4月22日 下午3.53.30.png
  1. 在ViewController里面添加TableView

设置TableView的代理


10张图告诉你Storyboard的强大!_第4张图片
47D183E5-D62D-4928-84BD-D14AEF9809E5.png

在UINavigationcontroller 的RootViewController的View视图只添加TableView 有 留白 的问题


record4.gif

10张图告诉你Storyboard的强大!_第5张图片
B2E6E945-3770-427D-8652-07EA74E1DB76.png

解决办法:在添加TableView之前添加一个任意视图

10张图告诉你Storyboard的强大!_第6张图片
B5DF0F4C-BA8E-4E4F-8EE4-C0AC4B94BE12.png

XIB直接关联到ViewController

record5.gif

在Storyboard里控制返回

不传数据返回


record6.gif

不用协议代理携带数据返回,(注意gif中关联返回方法的地方)


10张图告诉你Storyboard的强大!_第7张图片
A.png

10张图告诉你Storyboard的强大!_第8张图片
B.png

record7.gif

在Storyboard里控制预览你的代码

IBInspectable
在OC中使用IBInspectable,在swift中使用@IBInspectable。用它修饰的属性或者实例变量,可以显示在xib中的属性栏中

10张图告诉你Storyboard的强大!_第9张图片
IBInspectable.png
@interface ViewController : UIViewController

//gj_testFlag用IBInspectable修饰后,就能在xib中看到这个属性了,当然也可以用xib进行赋    值了
@property (assign, nonatomic) IBInspectable BOOL gj_testFlag;

@end

IB_DESIGNABLE
在OC中将IB_DESIGNABLE写在@implementation前,在swift中将@IBDesignable写在class前
它的作用是可以在不运行的情况下把你的代码显示在xib或SB文件中。

  1. 这是一个针对UI显示的功能,所以只能是在UIView及其子类或者NSView及其子类上生效。
  2. 要想使IBDesignable起作用必须把代码写在drawRect里才能显示,同样的代码,我写在了awakeFromNib里就不会再xib中看出效果,只有写在了drawRect才可以。
10张图告诉你Storyboard的强大!_第10张图片
IB_DESIGNABLE.png
IB_DESIGNABLE
@implementation TestView

- (void)drawRect:(CGRect)rect {
UIBezierPath *firtPath = 
[UIBezierPath bezierPathWithOvalInRect:CGRectMake(10, 10, 180, 180)];
CAShapeLayer *shapeL = [CAShapeLayer layer];
shapeL.lineWidth = 20;
shapeL.path =firtPath.CGPath;
shapeL.strokeStart = 0;
shapeL.strokeEnd = 1;
shapeL.strokeColor = [UIColor yellowColor].CGColor;
shapeL.fillColor = [UIColor clearColor].CGColor;
[self.layer addSublayer:shapeL];
self.layer.cornerRadius = 30;
self.layer.masksToBounds = YES;
}

@end

在Storyboard国际化

10张图告诉你Storyboard的强大!_第11张图片
add.png
10张图告诉你Storyboard的强大!_第12张图片
add1.png
10张图告诉你Storyboard的强大!_第13张图片
add2.png
10张图告诉你Storyboard的强大!_第14张图片
add3.png

在Storyboard的Runtime Attribute

10张图告诉你Storyboard的强大!_第15张图片
Runtime1.png

10张图告诉你Storyboard的强大!_第16张图片
Runtime2.png

在Storyboard关联NSObject

1.我们先建立一个Person类,继承自NSObject。
2.我们在Person类中添加一个简单的测试方法:
- (IBAction)sayHello:(id)sender { NSLog(@"hello person");}

3.我们在一个VC中添加这样的代码:
#import "Person.h"
@interface ViewController : UIViewController
@property (nonatomic, strong) IBOutlet Person *aPerson;
@end
4.我们找到ViewController对应的xib或SB文件,拖入一个button,把这个button与Person类
中的sayHello:函数“连线”,你发现根本连接不上
5.在右边栏中找到Object这个对象,拖动它到左侧边栏中,把Object对象的class设置为 Person,大功告成!

show.gif

如果有些地方你不是很明白,这里有更详细的教程!

你可能感兴趣的:(10张图告诉你Storyboard的强大!)