iOS开发笔记-tabbar图标设成用户头像
来源:互联网 发布:淘宝卖家套餐怎么设置 编辑:程序博客网 时间:2024/05/18 02:03
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;
// });
}
- iOS开发笔记-tabbar图标设成用户头像
- iOS开发中设置tabbar选中图标的颜色
- iOS开发笔记2 - 自定义tabbar
- iOS tabbar加小图标
- TabBar图标加载不了 -iOS
- iOS 开发 自定义Tabbar
- iOS开发: 自定义tabBar
- iOS 开发APP更换用户头像问题的处理方式
- ios --- Tabbar 的图标模糊问题
- IOS TabBar 点击不显示图标
- iOS开发上传头像
- iOS更换用户头像失败
- iOS开发中 自定义TabBar
- IOS开发UI:自定义TabBar
- iOS开发, tabbar自定义图片
- 微信开发笔记:获取用户openid,以及用户头像昵称等信息
- iOS开发之圆形头像
- iOS开发swift如何调用系统相册和相机获取图片设置用户头像
- Webpower携手梅花网,打造优雅的SaaS产品服务
- Android开发 模块化编程之引用本地的aar
- 求无序序列每个元素最接近的值
- PL/SQL教程
- tomcat利用setenv对内存的限制和docker中tomcat内存的优雅配置
- iOS开发笔记-tabbar图标设成用户头像
- JAVA方法耗时信息捕捉并日志
- Mapeduce编程八大步骤
- js和jquery获取各种宽度和盖度
- s:url标签使用
- padding和margin两个重要属性的介绍及举例
- 利用newFixedThreadPool来设计一个线程管理类
- tar命令
- 对jQuery插件的一点点认识