听说是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张图,展示一下效果