iOS——给UIView的CALayer层添加渐变效果
来源:互联网 发布:淘宝下单流程图 编辑:程序博客网 时间:2024/05/21 22:23
import “ViewController.h”
@interface ViewController ()
@end
@implementation ViewController
{
CAGradientLayer *_gradientLayer;
UIView *_layerView;
UIImageView *_imageView;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.view.backgroundColor = [UIColor blueColor];
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(10, 350, 150, 100)];
[button setTitle:@”显示/隐藏标题” forState:UIControlStateNormal];
[button addTarget:self action:@selector(buttonPressed) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
_imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@”test”]];
_imageView.frame = CGRectMake(0, 0, 320, 320);
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 25, 320, 100)];
label.text = @”我是标题标题标题!”;
label.textColor = [UIColor whiteColor];
_layerView = [[UIView alloc] initWithFrame:CGRectMake(0, 320-100, 320, 100)];
_gradientLayer = [CAGradientLayer layer]; // 设置渐变效果
_gradientLayer.bounds = _layerView.bounds;
_gradientLayer.borderWidth = 0;
_gradientLayer.frame = _layerView.bounds;
_gradientLayer.colors = [NSArray arrayWithObjects:
(id)[[UIColor clearColor] CGColor],
(id)[[UIColor blackColor] CGColor], nil];
_gradientLayer.startPoint = CGPointMake(0.5, 0.5);
_gradientLayer.endPoint = CGPointMake(0.5, 1.0);
[_layerView.layer insertSublayer:_gradientLayer atIndex:0];
[_imageView addSubview:_layerView];
[_layerView addSubview:label];
[self.view addSubview:_imageView];
}
- (void)buttonPressed
{
static BOOL yesOrNo = YES;
if (yesOrNo) {
[_layerView removeFromSuperview];
} else {
[_imageView addSubview:_layerView];
}
yesOrNo = !yesOrNo;
}
@end
- iOS——给UIView的CALayer层添加渐变效果
- ios—CAlayer层的属性
- ios-day18-02(通过CALayer做出跟UIImageView一样的效果、UIView和CALayer如何选择)
- iOS的UIView和CALayer
- iOS给UIView添加常用的Extension
- iOS 为UIView添加渐变色的两种方法
- 给UIview添加阴影效果
- 给UIView添加阴影效果
- iOS开发UI篇—CAlayer层的属性
- iOS开发UI篇—CAlayer层的属性
- iOS开发UI篇—CAlayer层的属性
- iOS开发UI篇—CAlayer层的属性
- iOS开发UI篇—CAlayer层的属性
- iOS开发UI高级—30CAlayer层的属性
- iOS开发UI篇—CAlayer层的属性
- iOS开发UI篇—CAlayer层的属性
- iOS开发UI篇—CAlayer层的属性
- iOS开发UI篇—CAlayer层的属性
- eclipse利用Hibernate Tools生成Hibernate Mapping文件及PO类
- Hive Sql 常用语句
- c#解析一个嵌套json的例子
- 十大算法
- Android WebView简单使用
- iOS——给UIView的CALayer层添加渐变效果
- Union-find
- (⊙o⊙)…
- ArcGis9.3在Layout View中如何将地图横过来
- 机器学习公开课笔记(5):神经网络(Neural Network)——学习
- Java中@ 的作用
- 神一般的C语言指针,你看懂多少?
- 【splay】BZOJ 3223 文艺平衡树
- 源码角度深入理解Activity