0
点赞
收藏
分享

微信扫一扫

iOS 头文件 只读属性



//头文件
//@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




举报

相关推荐

0 条评论