iOS开发笔记-tabbar图标设成用户头像
2015-11-24 17:03
316 查看
1.获取图片,并处理图片存储本地
UIImage *head = [UIImage imageWithData:imageData];
UIImage* head1 = [head image:head byScalingToSize:CGSizeMake(30, 30)];
UIImage* head2 = [head image:head byScalingToSize:CGSizeMake(60, 60)];
UIImage* head3 = [head image:head byScalingToSize:CGSizeMake(90, 90)];
//关于处理图片的方法,详见这篇博客 http://blog.csdn.net/jp940110jpjp/article/details/48629431
UIImage *resultImage1 = [head1 roundedRectImage:head1 withradius:head1.size.width/2.0 cornerMask:UIImageRoundedCornerTopLeft|UIImageRoundedCornerTopRight|UIImageRoundedCornerBottomLeft|UIImageRoundedCornerBottomRight];
UIImage *resultImage2 = [head2 roundedRectImage:head2 withradius:head2.size.width/2.0 cornerMask:UIImageRoundedCornerTopLeft|UIImageRoundedCornerTopRight|UIImageRoundedCornerBottomLeft|UIImageRoundedCornerBottomRight];
UIImage *resultImage3 = [head3 roundedRectImage:head3 withradius:head3.size.width/2.0 cornerMask:UIImageRoundedCornerTopLeft|UIImageRoundedCornerTopRight|UIImageRoundedCornerBottomLeft|UIImageRoundedCornerBottomRight];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *home = [paths objectAtIndex:0];
//设置一个图片的存储路径,tabbar需要@1x,@2x,@3x的图片所以,我们需要处理成相应的尺寸并存起来
NSString *imagePath1 = [home stringByAppendingString:@"/tabbar.png"];
NSString *imagePath2 = [home stringByAppendingString:@"/tabbar@2x.png"];
NSString *imagePath3 = [home stringByAppendingString:@"/tabbar@3x.png"];
//把图片直接保存到指定的路径(同时应该把图片的路径imagePath存起来,下次就可以直接用来取)
[UIImagePNGRepresentation(resultImage1) writeToFile:imagePath1 atomically:YES];
[UIImagePNGRepresentation(resultImage2) writeToFile:imagePath2 atomically:YES];
[UIImagePNGRepresentation(resultImage3) writeToFile:imagePath3 atomically:YES];
2.读取图片并加载
UIImage *tabbarImage;
UIImage *tabSelectedImage;
if (isLogin) {
tabbarImage = [JPDealTabImage shoudUseImage];
tabSelectedImage = tabbarImage;
}else{
tabbarImage = [UIImage imageNamed:@"my_normal.png"];
tabSelectedImage =[UIImage imageNamed:@"my_selected.png"];
}
UIColor *tabbarColor = [UIColor colorWithRed:0xef/255.0 green:0x7f/255.0 blue:0x5e/255.0 alpha:1];
self.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"我的" image:[tabbarImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[tabSelectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[self.tabBarItem setTitleTextAttributes:[NSDictionary
dictionaryWithObjectsAndKeys:[UIColor colorWithRed:0x63/255.0 green:0x57/255.0 blue:0x53/255.0 alpha:1],
NSForegroundColorAttributeName, nil] forState:UIControlStateNormal];
[self.tabBarItem setTitleTextAttributes:[NSDictionary
dictionaryWithObjectsAndKeys:tabbarColor,
NSForegroundColorAttributeName, nil] forState:UIControlStateSelected];
//读取图片
+(UIImage *)shoudUseImage{
// dispatch_async(dispatch_get_global_queue(0, 0), ^{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *home = [paths objectAtIndex:0];
//设置一个图片的存储路径 stringByAppendingString:@/Documents/flower.png
NSString *imagePath1 = [home stringByAppendingString:@"/tabbar.png"];
NSString *imagePath2 = [home stringByAppendingString:@"/tabbar@2x.png"];
NSString *imagePath3 = [home stringByAppendingString:@"/tabbar@3x.png"];
UIImage *head;
if (WIDTH == 414) {
head = [UIImage imageWithContentsOfFile:imagePath3];
}else{
if (isRetina) {
head = [UIImage imageWithContentsOfFile:imagePath2];
}else{
head = [UIImage imageWithContentsOfFile:imagePath1];
}
}
return head;
// });
}
UIImage *head = [UIImage imageWithData:imageData];
UIImage* head1 = [head image:head byScalingToSize:CGSizeMake(30, 30)];
UIImage* head2 = [head image:head byScalingToSize:CGSizeMake(60, 60)];
UIImage* head3 = [head image:head byScalingToSize:CGSizeMake(90, 90)];
//关于处理图片的方法,详见这篇博客 http://blog.csdn.net/jp940110jpjp/article/details/48629431
UIImage *resultImage1 = [head1 roundedRectImage:head1 withradius:head1.size.width/2.0 cornerMask:UIImageRoundedCornerTopLeft|UIImageRoundedCornerTopRight|UIImageRoundedCornerBottomLeft|UIImageRoundedCornerBottomRight];
UIImage *resultImage2 = [head2 roundedRectImage:head2 withradius:head2.size.width/2.0 cornerMask:UIImageRoundedCornerTopLeft|UIImageRoundedCornerTopRight|UIImageRoundedCornerBottomLeft|UIImageRoundedCornerBottomRight];
UIImage *resultImage3 = [head3 roundedRectImage:head3 withradius:head3.size.width/2.0 cornerMask:UIImageRoundedCornerTopLeft|UIImageRoundedCornerTopRight|UIImageRoundedCornerBottomLeft|UIImageRoundedCornerBottomRight];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *home = [paths objectAtIndex:0];
//设置一个图片的存储路径,tabbar需要@1x,@2x,@3x的图片所以,我们需要处理成相应的尺寸并存起来
NSString *imagePath1 = [home stringByAppendingString:@"/tabbar.png"];
NSString *imagePath2 = [home stringByAppendingString:@"/tabbar@2x.png"];
NSString *imagePath3 = [home stringByAppendingString:@"/tabbar@3x.png"];
//把图片直接保存到指定的路径(同时应该把图片的路径imagePath存起来,下次就可以直接用来取)
[UIImagePNGRepresentation(resultImage1) writeToFile:imagePath1 atomically:YES];
[UIImagePNGRepresentation(resultImage2) writeToFile:imagePath2 atomically:YES];
[UIImagePNGRepresentation(resultImage3) writeToFile:imagePath3 atomically:YES];
2.读取图片并加载
UIImage *tabbarImage;
UIImage *tabSelectedImage;
if (isLogin) {
tabbarImage = [JPDealTabImage shoudUseImage];
tabSelectedImage = tabbarImage;
}else{
tabbarImage = [UIImage imageNamed:@"my_normal.png"];
tabSelectedImage =[UIImage imageNamed:@"my_selected.png"];
}
UIColor *tabbarColor = [UIColor colorWithRed:0xef/255.0 green:0x7f/255.0 blue:0x5e/255.0 alpha:1];
self.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"我的" image:[tabbarImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[tabSelectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[self.tabBarItem setTitleTextAttributes:[NSDictionary
dictionaryWithObjectsAndKeys:[UIColor colorWithRed:0x63/255.0 green:0x57/255.0 blue:0x53/255.0 alpha:1],
NSForegroundColorAttributeName, nil] forState:UIControlStateNormal];
[self.tabBarItem setTitleTextAttributes:[NSDictionary
dictionaryWithObjectsAndKeys:tabbarColor,
NSForegroundColorAttributeName, nil] forState:UIControlStateSelected];
//读取图片
+(UIImage *)shoudUseImage{
// dispatch_async(dispatch_get_global_queue(0, 0), ^{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *home = [paths objectAtIndex:0];
//设置一个图片的存储路径 stringByAppendingString:@/Documents/flower.png
NSString *imagePath1 = [home stringByAppendingString:@"/tabbar.png"];
NSString *imagePath2 = [home stringByAppendingString:@"/tabbar@2x.png"];
NSString *imagePath3 = [home stringByAppendingString:@"/tabbar@3x.png"];
UIImage *head;
if (WIDTH == 414) {
head = [UIImage imageWithContentsOfFile:imagePath3];
}else{
if (isRetina) {
head = [UIImage imageWithContentsOfFile:imagePath2];
}else{
head = [UIImage imageWithContentsOfFile:imagePath1];
}
}
return head;
// });
}
相关文章推荐
- 按右键另存图片只能存BMP
- photoshop去除图片上的水印
- upload上传单张图片
- 图片引发的溢出危机(图)
- C#实现把彩色图片灰度化代码分享
- C#将图片和字节流互相转换并显示到页面上
- C#监控文件夹并自动给图片文件打水印的方法
- 纯CSS实现的当鼠标移上图片添加阴影效果代码
- C#实现打开画图的同时载入图片、最大化显示画图窗体的方法
- 随鼠标移动的图片或文字特效代码
- CSS 图片横向排列实现代码
- C#实现将Email地址转成图片显示的方法
- 超级经典一套鼠标控制左右滚动图片带自动翻滚
- 用css实现图片垂直居中的使用技巧
- C++实现读取图片长度和宽度
- PHP根据图片色界在不同位置加水印的方法
- php通过修改header强制图片下载的方法
- PHP安全上传图片的方法
- 使用GD库生成带阴影文字的图片
- php获取网页里所有图片并存入数组的方法