聽說是xcode4.3之前會用到的,好老舊的知識了。不過在現在的xcode當中依然可以使用,不過已經不推薦了!稍微記錄一下,萬一碰到老項目不知道如何下手咋辦呢?
1、自定義一個UIView,例如UILabel之類的。本人在此自定義一個UILabel
//
// SZLabel.h
// IB代碼測試
//
// Created by styshy on 15/11/28.
// Copyright © 2015年 sz. All rights reserved.
//
#import <UIKit/UIKit.h>
// 自己設計一個屬性
IB_DESIGNABLE
@interface SZLabel : UILabel
// 如果想要屬性在stroyboard或者xib中顯示,需要設置IBInspectable
@property (nonatomic,copy) IBInspectable NSString *showMessage;
@property (nonatomic,assign) IBInspectable float abc;
@end
2、以上步驟僅僅是完成了屬性可以在storyboard或xib中顯示,但是並沒有完成屬性和自定義控件屬性的綁定。比如設置label的文本內容爲屬性的值。這樣屬性和控件建立聯繫之後可以讓屬性的值實時顯示在控件上
//
// SZLabel.m
// IB代碼測試
//
// Created by styshy on 15/11/28.
// Copyright © 2015年 sz. All rights reserved.
//
#import "SZLabel.h"
@implementation SZLabel
- (void)setshowMessage:(NSString *)showMessage{
_showMessage = showMessage;
self.text = [NSString stringWithFormat:@"%@,%0.1f",showMessage,self.abc];
}
@end
3、簡單截了2張圖,展示一下效果