网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

ios开发uiimage,iOs开发高级工程师

(IOS)设置UIImage的透明度

// 方法一、添加UIImage分类

创新互联公司专注为客户提供全方位的互联网综合服务,包含不限于网站制作、网站建设、桂平网络推广、微信小程序开发、桂平网络营销、桂平企业策划、桂平品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;创新互联公司为所有大学生创业者提供桂平建站搭建服务,24小时服务热线:18980820575,官方网址:www.cdcxhl.com

- (UIImage*)imageByApplyingAlpha:(CGFloat) alpha {

UIGraphicsBeginImageContextWithOptions(self.size,NO,0.0f);

CGContextRef ctx = UIGraphicsGetCurrentContext();

CGRectarea = CGRectMake(0,0,self.size.width,self.size.height);

CGContextScaleCTM(ctx, 1, -1);

CGContextTranslateCTM(ctx, 0, -area.size.height);

CGContextSetBlendMode(ctx, kCGBlendModeMultiply);

CGContextSetAlpha(ctx, alpha);

CGContextDrawImage(ctx, area,self.CGImage);

UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

returnnewImage;

}

// 方法二、如果没有奇葩需求,干脆用UIImageView设置透明度

UIImageView*imageView = [[UIImageViewalloc]initWithImage:[UIImageimageWithName:@"yourImage"]];

imageView.alpha =0.5;

iOS开发网络篇-UIImage加载图片方式

imageNamed默认加载图片成功后会内存中缓存图片,这个方法用一个指定的名字在系统缓存中查找并返回一个图片对象.如果缓存中没有找到相应的图片对象,则从指定地方加载图片然后缓存对象,并返回这个图片对象.多了就有问题。一般加上AutoReleasePool

imageWithContentsOfFile则仅只加载图片,不缓存.大量使用imageNamed方式会在不需要缓存的地方额外增加开销CPU的时间来做这件事.当应用程序需要加载一张比较大的图片并且使用一次性,那么其实是没有必要去缓存这个图片的,用imageWithContentsOfFile是最为经济的方式,这样不会因为UIImage元素较多情况下,CPU会被逐个分散在不必要缓存上浪费过多时间.。

iOS 开发-UIImageViews(图片)的使用

UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bgImage"]]; 

创建并设置默认图, 也可以

UIImageView*imageView = [[UIImageView alloc] init];

imageView.image= [UIImageimageNamed:@"bgImage"];

还可以这样先设置imageview的大, 在设置图片

UIImageView*imageView = [[UIImageView alloc] initWithFrame:(CGRectMake(0,144,SCREEN_Width,50))];

imageView.image= [UIImageimageNamed:@"bgImage"];

由此可看imageview的frame可以这样设置

imageView.frame=CGRectMake(0,144,SCREEN_Width,50);

通常我们使用的的imageview都会添加圆角边框

imageView.layer.masksToBounds = YES;

imageView.layer.cornerRadius=25;

imageView.layer.borderColor = [UIColor blueColor].CGColor;

imageView.layer.borderWidth=1;

这个圆角和边框像view和label以及button的设置方式都是一样的 当然imageview也一样

imageView.backgroundColor= [UIColorclearColor]; 图片设置背景颜色, 我通常使用clearColor  透明

 imageView.userInteractionEnabled = YES; 图片设置成可交互, 设置为NO则不能交互

[self.viewaddSubview: imageView]; 添加视图也可叫做显示视图

设置图片内容的布局方式 imageView.contentMode

这个属性是用来设置图片的显示方式,如居中、居右,是否缩放等

imageView.contentMode = UIViewContentModeScaleAspectFit;

UIViewContentMode contentMode枚举类型

    (1)  UIViewContentModeScaleToFill;     默认,对图片进行拉伸处理(不是按比例),是充满bouns

  (2)  UIViewContentModeScaleAspectFit;     按原图比例进行拉伸,是图片完全展示在bouns中

    (3)  UIViewContentModeScaleAspectFill;     按原图比例填充,使图片展示在bouns中,可能只显示部分

    (4)  UIViewContentModeRedraw;     重划边界变化(重设 - setNeedsDisplay)

    (5)  UIViewContentModeCenter;     图片显示在imageview的正中间,原图大小

    (6)  UIViewContentModeTop;     图片显示在imageview的上部,原图大小

    (7)  UIViewContentModeBottom;     图片显示在imageview的下部,原图大小

    (8)  UIViewContentModeLeft;     图片显示在imageview的左部,原图大小

    (9)  UIViewContentModeRight;     图片显示在imageview的右部,原图大小

    (10)  UIViewContentModeTopLeft;     图片显示在imageview的左上部,原图大小

    (11)  UIViewContentModeTopRight;     图片显示在imageview的右上部,原图大小

    (12)  UIViewContentModeBottomLeft;     图片显示在imageview的左下部,原图大小

    (13)  UIViewContentModeBottomRight;     图片显示在imageview的右下部,原图大小

imageView.alpha = 1.0;    设置图片透明度

   NSString *path1 = [[NSBundle mainBundle] pathForResource:@"1" ofType:@"jpg"];

   NSString *path2 = [[NSBundle mainBundle] pathForResource:@"2" ofType:@"jpg"];

   NSString *path3 = [[NSBundle mainBundle] pathForResource:@"3" ofType:@"jpg"];

   imageView.animationImages = @[[UIImage imageWithContentsOfFile:path1],[UIImage imageWithContentsOfFile:path2],[UIImage imageWithContentsOfFile:path3]];

   imageView.animationDuration = 5.0f;    设置循环一次的时间

   imageView.animationRepeatCount = 0;    // 设置循环次数(0为无线循环)

   [imageView startAnimating];            // 开始动画

   [imageView stopAnimating];              // 停止动画

NSData *imageData = [NSData dataWithContentsOfFile:path];

UIImage *image4 = [UIImage imageWithData:imageData];

NSString *path = [[NSBundle mainBundle] pathForResource:@"1" ofType:@"jpg"];

UIImage *image2 = [UIImage imageWithContentsOfFile:path];

ImageView.hidden = NO;    隐藏或者显示图片 YES为隐藏

[ImageView sizeToFit];    将图片尺寸调整为与内容图片相同

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapImageView:)]; // 设置手势

[ImageView addGestureRecognizer:singleTap]; // 给图片添加手势


网页名称:ios开发uiimage,iOs开发高级工程师
文章链接:http://bjjierui.cn/article/hoidsi.html

其他资讯