CALayer 是一個很常用的到的 Object,很經常使用,也很重要,同時又有比較多的屬性,嗯,必定要詳細瞭解下 php
CALayer 的原理很難懂,因爲我目前只注重運用,因此就說那些在實際開發中能用到的一些地方 測試
- (void)viewDidLoad { [super viewDidLoad]; UIView *viewSample = [[UIView alloc] init]; [self.view addSubview:viewSample]; viewSample.backgroundColor = [UIColor greenColor]; viewSample.frame = CGRectMake(100, 100, 400, 400); //Test 1 陰影 //viewSample.layer.shadowPath = [UIBezierPath bezierPathWithRect:viewSample.bounds].CGPath; viewSample.layer.shadowPath = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, 400, 400)].CGPath; viewSample.layer.masksToBounds = NO; viewSample.layer.shadowOffset = CGSizeMake(10, 10); viewSample.layer.shadowRadius = 5; viewSample.layer.shadowOpacity = 0.5; //Test 2 邊框 viewSample.layer.borderWidth = 2; viewSample.layer.borderColor = [[UIColor redColor] CGColor]; //Test 3 masksToBounds UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0,0, 500, 500)]; btn.backgroundColor = [UIColor lightGrayColor]; //[viewSample addSubview:btn]; //viewSample.layer.masksToBounds = true; //Test 4 bounds //viewSample.layer.bounds = CGRectMake(200, 200, 500, 500); //Test 5 viewSample.layer.opacity = 0.5; viewSample.layer.cornerRadius = 5; }