设为首页 加入收藏

TOP

IOS CALayer(一)(一)
2017-10-13 10:24:09 】 浏览:5932
Tags:IOS CALayer

对于一个app的好坏,我们首要判断的便是app的界面,而界面的建立则是在图形的处理基础上的,说到图形处理又不得不提及Quartz2D,CALayer。

在iOS系统中,你能看得见摸得着的东西基本上都是UIView,比如一个按钮、一个文本标签、一个文本输入框、一个图标等等,这些都是UIView。

其实UIView之所以能显示在屏幕上,完全是因为它内部的一个层。

在创建UIView对象时,UIView内部会自动创建一个层(即CALayer对象),通过UIView的layer属性可以访问这个层。当UIView需要显示到屏幕上时,会调用drawRect:方法进行绘图,并且会将所有内容绘制在自己的层上,绘图完毕后,系统会将层拷贝到屏幕上,于是就完成了UIView的显示。

 换句话说,UIView本身不具备显示的功能,是它内部的层才有显示功能。

首先展示一下无任何操作的imageView。

//
//  ViewController.m
//  CX - CALayer(一)
//
//  Created by ma c on 16/3/19.
//  Copyright © 2016年 xubaoaichiyu. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(50, 50, self.view.frame.size.width - 100, 400)];
    
    imageView.image = [UIImage imageNamed:@"nvshen.jpg"];
    
    [self.view addSubview:imageView];

}

@end

设置阴影的效果

 

//
//  ViewController.m
//  CX - CALayer(一)
//
//  Created by ma c on 16/3/19.
//  Copyright © 2016年 xubaoaichiyu. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(50, 50, self.view.frame.size.width - 100, 400)];
    
    imageView.image = [UIImage imageNamed:@"nvshen.jpg"];
    //设置阴影的颜色
    imageView.layer.shadowColor = [UIColor orangeColor].CGColor;
    //设置阴影的偏移量
    imageView.layer.shadowOffset = CGSizeMake(5, 5);
    //设置阴影的透明度,1为不透明。
    imageView.layer.shadowOpacity = 0.5;

    [self.view addSubview:imageView];

}

@end

 

设置圆角的效果

//
//  ViewController.m
//  CX - CALayer(一)
//
//  Created by ma c on 16/3/19.
//  Copyright © 2016年 xubaoaichiyu. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(50, 50, self.view.frame.size.width - 100, 400)];
    
    imageView.image = [UIImage imageNamed:@"nvshen.jpg"];
//    //设置阴影的颜色
//    imageView.layer.shadowColor = [UIColor orangeColor].CGColor;
//    //设置阴影的偏移量
//    imageView.layer.shadowOffset = CGSizeMake(5, 5);
//    //设置阴影的透明度,1为不透明。
//    imageView.layer.shadowOpacity = 0.5;
    //设置圆角的半径
    imageView.layer.cornerRadius= 10;
    //使视图支持圆角
    imageView.layer.masksToBounds = YES;
    //masksToBounds 设置为YES 阴影效果将失效。
    
    [self.view addSubview:imageView];

}

@end

 

设置边框的效果

//
//  ViewController.m
//  CX - CALayer(一)
//
//  Created by ma c on 16/3/19.
//  Copyright © 2016年 xubaoaichiyu. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(50, 50, self.view.frame.size.width - 100, 400)];
    
    imageView.image = [UIImage imageNamed:@"nvshen.jpg"];
//    //设置阴影的颜色
//    imageView.layer.shadowColor = [UIColor or
首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇分页(进行封装处理) 下一篇iOS开发中的几种设计模式介绍

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目