您的位置:首页 > 移动开发 > IOS开发

iOS 头文件 只读属性

2017-05-22 18:45 190 查看
//头文件
//@property (nonatomic, readonly) UIView *headView;

#import "ViewController.h"

@interface ViewController ()
{
UIView *_headView;
}

@end

@implementation ViewController

//MRC
//@property 特性是由xcode自动生成setter和getter方法的声明
//@synthesize 特性是由xcode自动生成setter和getter方法的定义

//在ARC下,@property则做了2件事:
//1. 由@property声明的属性,在编译时刻为其生成成员变量(_XXX),除非,声明一个与属性同名的成员变量,则不会自动生成相应的_XXX成员变量。
//2. 由@property声明的属性,在编译时刻为其生成getter和setter方法的声明与定义。

//Objective-C语言,通过@synthesize生成getter和setter方法.

@synthesize headView = _headView;

- (void)viewDidLoad {

_headView = [UIView new];
_headView.frame = self.view.bounds;
[self.view addSubview:_headView];

[super viewDidLoad];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
self.headView.backgroundColor = [UIColor cyanColor];
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: