iOS实现渐变颜色
下面是我的两种实现:
1.直接图片展示,注意图片的变形问题;
2.用CAGradientLayer渐变颜色实现;
代码如下:
//
// ViewController.m
// ImageStrenchDemo
//
// Created by 思 彭 on 17/3/14.
// Copyright © 2017年 思 彭. All rights reserved.
// #import "ViewController.h" // rgb颜色转换(16进制->10进制)
#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0] @interface ViewController () @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; UIImageView *headImgViewBg = [[UIImageView alloc] initWithFrame:self.view.bounds];
[headImgViewBg setImage:[UIImage imageNamed:@"bj"]];
[self.view addSubview:headImgViewBg];
[self setupUI];
[self setupImage]; } // 图片实现渐变
- (void)setupImage { UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(, , , );
UIImage *image1 = [UIImage imageNamed:@""];
UIImage *resizeImage = [image1 resizableImageWithCapInsets:UIEdgeInsetsMake(image1.size.height*0.5, image1.size.width*0.3, image1.size.height*0.5, image1.size.width*0.5)resizingMode:UIImageResizingModeStretch];
[button setBackgroundImage:resizeImage forState:UIControlStateNormal ];
[button setTitle:@"dcevbvhvjrvrjvn" forState:UIControlStateNormal];
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[self.view addSubview:button];
} // 颜色值实现渐变
- (void)setupUI { UIView *bgView = [[UIView alloc]initWithFrame:CGRectMake(, , , )];
UIImageView *headImgViewBg = [[UIImageView alloc] initWithFrame:CGRectMake(, , , )];
bgView.layer.masksToBounds = YES;
bgView.layer.cornerRadius = ;
[bgView addSubview:headImgViewBg];
[self.view addSubview:bgView];
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = headImgViewBg.frame;
gradient.colors = [NSArray arrayWithObjects:(id)UIColorFromRGB(0x752ccd).CGColor,
(id)UIColorFromRGB(0xcd1f87).CGColor,nil];
gradient.startPoint = CGPointMake(, 0.5);
gradient.endPoint = CGPointMake(, 0.5);
[headImgViewBg.layer insertSublayer:gradient atIndex:];
} @end
iOS实现渐变颜色的更多相关文章
- 【原】Github系列之三:开源iOS下 渐变颜色的进度条WGradientProgress
概述 今天我们来实现一个iOS平台上的进度条(progress bar or progress view).这种进度条比APPLE自带的更加漂亮,更加有“B格”.它拥有渐变的颜色,而且这种颜色是动态移 ...
- 渐变颜色的进度条WGradientProgress-备用
今天我们来实现一个iOS平台上的进度条(progress bar or progress view).这种进度条比APPLE自带的更加漂亮,更加有“B格”.它拥有渐变的颜色,而且这种颜色是动态移动的, ...
- iOS中的颜色
最近在改Bug的时候,才注意到iOS 中的颜色竟然也大有文章,特来记录一下. 先说一下问题,因为某界面中有用xib实现的一个view,而这个view 只在UIColletionView的layout ...
- 32.QT-制作最强电压电阻表盘,可以自定义阴影效果,渐变颜色,图标,文字标签等-附带demo程序
由于上位机需要绘制电压电阻表盘,如下图所示: 后来,在网上找阿找,还是没找到满意的,索性自己来画控件算了,由于第一次画控件,所以花了我2天时间,才画好 效果图如下: 上图的所有颜色(包括滑动的渐变/单 ...
- CAGradientLayer渐变颜色动画
CAGradientLayer渐变颜色动画 或许你用过CAGradientLayer,你知道他是用于渐变颜色的,但你是否直到,CAGradientLayer的渐变颜色是可以动画的哦. 源码: // / ...
- 跟我一起玩Win32开发(23):渐变颜色填充
GradientFill函数可以对特定的矩形区域或者三角形区域进行渐变颜色的填充.我们先来看看GradientFill函数到底长得什么样子,帅不帅. BOOL GradientFill( _In_ ...
- iOS圆弧渐变进度条的实现
由于项目需要一个环形渐变进度条显示课程,这方便网上的确有很多相关资料但是,都是比较零散的而且,大多数只是放一堆代码就算完了.这里我想详细写一篇我自己实现这个进度条的过程. 实现一个圆弧进度条主要分为三 ...
- win2d 渐变颜色
本文告诉大家如何在 win2d 使用渐变颜色 线条渐变 在 UWP 的 Win2d 使用渐变颜色需要 CanvasLinearGradientBrush 做颜色,本文告诉大家如何在 win2d 使用 ...
- 好看的css渐变颜色大全网址
60个渐变颜色 https://webkul.github.io/coolhue/ 60个非常有用的CSS代码片段 https://baijiahao.baidu.com/s?id=160278735 ...
随机推荐
- Number of Parallelograms CodeForces - 660D (几何)
Number of Parallelograms CodeForces - 660D You are given n points on a plane. All the points are dis ...
- 【安徽集训】Emerald
Description \(n\) 座城市在数轴上,第 \(i\) 座城市有一条连向第 \(i+1\) 座城市的单向边.每座城市有一个类型 A/B 以及一个非负整数人口,A 类城市的人觉得自己的城市比 ...
- unbutu apt-get update失败及解决办法
今天在用apt-get update更新时一直失败,报的错误为”Failed to fetch 404 Not Found”,因为我的镜像改为了mirrors.aliyun.com 我试着ping了一 ...
- CSS基础学习-10.CSS伸缩盒(老版本)
- LeetCode 01 两数之和
链接:https://leetcode-cn.com/problems/two-sum 给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们 ...
- Docuemnt 的 NamespaceURI为空问题
创建doc的方式不同,需要增加 DocumentBuilderFactory.setNamespaceAware(true); 这样Element Node.getNamespaceURI 才不为空 ...
- 浮动float和清除clear
一.浮动(float) float简介 取值:left,right,none,inherit,默认none(不浮动) 可应用与所有元素 没有继承性 不在正常流中,但会影响布局.因为一个元素浮动时,其他 ...
- JavaScript赋值运算符
赋值运算符 ⑴ "=" 赋值符号 可以将符号右侧的值赋值给符号左侧的变量 ⑵ "+=" 加等于,是一个运算符 不要分开写 a += 5 等价 ...
- IT行业常见职位英文缩写
1.PG Programer 程序员 2.AA ...
- java上传大文件解决方案
需求:项目要支持大文件上传功能,经过讨论,初步将文件上传大小控制在10G内,因此自己需要在项目中进行文件上传部分的调整和配置,自己将大小都以10G来进行限制. 第一步: 前端修改 由于项目使用的是BJ ...