10張圖告訴你Storyboard的強(qiáng)大!

Storyboard對TableView的強(qiáng)力支持

  1. 為tableview添加headview,footview
record1.gif

運(yùn)行圖
  1. Storyboard直接關(guān)聯(lián)cell

創(chuàng)建cell文件,并與storyboard視圖cell關(guān)聯(lián),并設(shè)置復(fù)用標(biāo)識


record2.gif

關(guān)聯(lián)屬性


record3.gif

Simulator Screen Shot 2016年4月22日 下午3.53.30.png
  1. 在ViewController里面添加TableView

設(shè)置TableView的代理


47D183E5-D62D-4928-84BD-D14AEF9809E5.png

在UINavigationcontroller 的RootViewController的View視圖只添加TableView 有 留白 的問題


record4.gif

B2E6E945-3770-427D-8652-07EA74E1DB76.png

解決辦法:在添加TableView之前添加一個(gè)任意視圖

B5DF0F4C-BA8E-4E4F-8EE4-C0AC4B94BE12.png

XIB直接關(guān)聯(lián)到ViewController

record5.gif

在Storyboard里控制返回

不傳數(shù)據(jù)返回


record6.gif

不用協(xié)議代理攜帶數(shù)據(jù)返回,(注意gif中關(guān)聯(lián)返回方法的地方)


A.png

B.png

record7.gif

在Storyboard里控制預(yù)覽你的代碼

IBInspectable
在OC中使用IBInspectable,在swift中使用@IBInspectable。用它修飾的屬性或者實(shí)例變量,可以顯示在xib中的屬性欄中

IBInspectable.png
@interface ViewController : UIViewController

//gj_testFlag用IBInspectable修飾后,就能在xib中看到這個(gè)屬性了,當(dāng)然也可以用xib進(jìn)行賦    值了
@property (assign, nonatomic) IBInspectable BOOL gj_testFlag;

@end

IB_DESIGNABLE
在OC中將IB_DESIGNABLE寫在@implementation前,在swift中將@IBDesignable寫在class前
它的作用是可以在不運(yùn)行的情況下把你的代碼顯示在xib或SB文件中。

  1. 這是一個(gè)針對UI顯示的功能,所以只能是在UIView及其子類或者NSView及其子類上生效。
  2. 要想使IBDesignable起作用必須把代碼寫在drawRect里才能顯示,同樣的代碼,我寫在了awakeFromNib里就不會再xib中看出效果,只有寫在了drawRect才可以。
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國際化

add.png
add1.png
add2.png
add3.png

在Storyboard的Runtime Attribute

Runtime1.png

Runtime2.png

在Storyboard關(guān)聯(lián)NSObject

1.我們先建立一個(gè)Person類,繼承自NSObject。
2.我們在Person類中添加一個(gè)簡單的測試方法:
- (IBAction)sayHello:(id)sender { NSLog(@"hello person");}

3.我們在一個(gè)VC中添加這樣的代碼:
#import "Person.h"
@interface ViewController : UIViewController
@property (nonatomic, strong) IBOutlet Person *aPerson;
@end
4.我們找到ViewController對應(yīng)的xib或SB文件,拖入一個(gè)button,把這個(gè)button與Person類
中的sayHello:函數(shù)“連線”,你發(fā)現(xiàn)根本連接不上
5.在右邊欄中找到Object這個(gè)對象,拖動它到左側(cè)邊欄中,把Object對象的class設(shè)置為 Person,大功告成!

show.gif

如果有些地方你不是很明白,這里有更詳細(xì)的教程!

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容