解决 UIView 设置背景为UIImage图片变型问题[XXX setBackgroundColor:
2014-03-25 11:47
501 查看
[self.drawingView setBackgroundColor:[UIColor colorWithPatternImage:[self thumbnailWithImageWithoutScale:imagesize:self.drawingView.frame.size]]];
- (UIImage *)thumbnailWithImageWithoutScale:(UIImage *)image size:(CGSize)asize
{
UIImage *newimage;
if (nil == image)
{
newimage = nil;
}
else
{
CGSize oldsize = image.size;
CGRect rect;
if (asize.width/asize.height > oldsize.width/oldsize.height)
{
rect.size.width = asize.height*oldsize.width/oldsize.height;
rect.size.height = asize.height;
rect.origin.x = (asize.width - rect.size.width)/2;
rect.origin.y = 0;
}
else
{
rect.size.width = asize.width;
rect.size.height = asize.width*oldsize.height/oldsize.width;
rect.origin.x = 0;
rect.origin.y = (asize.height - rect.size.height)/2;
}
UIGraphicsBeginImageContext(asize);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [[UIColorclearColor] CGColor]);
UIRectFill(CGRectMake(0, 0, asize.width, asize.height));//clear background
[image drawInRect:rect];
newimage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
return newimage;
}
转载:http://www.cnblogs.com/Camier-myNiuer/archive/2013/12/03.html
Animating UIImageView with colorWithPatternImage
Leave your code as it is, but instead using
my subclass:
If you create the view using interface builder you only need to set the class of the image view in the identity inspector.
转载:http://stackoverflow.com/questions/16461469/animating-uiimageview-with-colorwithpatternimage
- (UIImage *)thumbnailWithImageWithoutScale:(UIImage *)image size:(CGSize)asize
{
UIImage *newimage;
if (nil == image)
{
newimage = nil;
}
else
{
CGSize oldsize = image.size;
CGRect rect;
if (asize.width/asize.height > oldsize.width/oldsize.height)
{
rect.size.width = asize.height*oldsize.width/oldsize.height;
rect.size.height = asize.height;
rect.origin.x = (asize.width - rect.size.width)/2;
rect.origin.y = 0;
}
else
{
rect.size.width = asize.width;
rect.size.height = asize.width*oldsize.height/oldsize.width;
rect.origin.x = 0;
rect.origin.y = (asize.height - rect.size.height)/2;
}
UIGraphicsBeginImageContext(asize);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [[UIColorclearColor] CGColor]);
UIRectFill(CGRectMake(0, 0, asize.width, asize.height));//clear background
[image drawInRect:rect];
newimage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
return newimage;
}
转载:http://www.cnblogs.com/Camier-myNiuer/archive/2013/12/03.html
Animating UIImageView with colorWithPatternImage
Leave your code as it is, but instead using
UIImageViewuse
my subclass:
// // AnimatedPatternView.h // #import <UIKit/UIKit.h> @interface AnimatedPatternView : UIImageView; @end
// // AnimatedPatternView.m // #import "AnimatedPatternView.h" @implementation AnimatedPatternView -(void)setAnimationImages:(NSArray *)imageArray { NSMutableArray* array = [NSMutableArray arrayWithCapacity:imageArray.count]; for (UIImage* image in imageArray) { UIGraphicsBeginImageContextWithOptions(self.bounds.size, YES, 0); UIColor* patternColor = [UIColor colorWithPatternImage:image]; [patternColor setFill]; CGContextRef ctx = UIGraphicsGetCurrentContext(); CGContextFillRect(ctx, self.bounds); UIImage *img = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); [array addObject:img]; } [super setAnimationImages:array]; } @end
If you create the view using interface builder you only need to set the class of the image view in the identity inspector.
转载:http://stackoverflow.com/questions/16461469/animating-uiimageview-with-colorwithpatternimage
相关文章推荐
- UE4射击小游戏原型
- uiview 动画
- Launcher3源码分析 — 主界面的UI结构
- skyline TerraBuilder 制作MPT方法与技巧(1)
- 《APUE》chapter 5 Standard I/O libary 学习笔记(加上自己的代码)
- 关于Build Active Architecture Only属性
- iOS GCD 与 NSOperationQueue
- 苹果拍照或者获取相册簿UIImagePickerController
- 黑马程序员_iOS 的高级控件之UITableView基本应用
- 黑马程序员_iOS 的高级控件之UIScrollView
- 见鬼的VS2012链接错误
- LigerUI真假分页以及过滤查询功能
- DuiLib的源码分析
- UILabel 的常见属性和方法:
- easyUI的window包含一个iframe,在iframe中如何关闭window?
- iOS Foundation框架 -3.利用NSNumber和NSValue将非OC对象类型数据存放到集合
- iPhone开发 UILocalNotification的使用
- 原生sql_query写入“\r\n”会保存为回车到数据库中
- 交互设计师:讨论几种处理问题的方法
- pentaho 在对中文query过滤时候报500错误,如何解决?