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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值