uitablar图片分辨率模糊问题

在项目中,发现tabbar设置的图片老是出现模糊的情况,查了一些资料还是没有解决,后来发现是没有适配Retina。

要想适配Retina不要美工处理3种格式的图片 30*30,@2x,@3x 三个尺寸的图片才行!

#import <UIKit/UIKit.h>

@interface TabBarViewController : UITabBarController

@end



#import "TabBarViewController.h"
#import "aaaViewController.h"

@implementation TabBarViewController

-(void)initControlles{
    
    aaaViewController  *aa = [[aaaViewController alloc] init];
    UINavigationController* ayNav = [[UINavigationController alloc]initWithRootViewController:aa];
    
    aaaViewController  *bb = [[aaaViewController alloc] init];
    UINavigationController* bNav = [[UINavigationController alloc]initWithRootViewController:bb];
    
    aaaViewController  *cc = [[aaaViewController alloc] init];
    
    
    UINavigationController* cNav = [[UINavigationController alloc]initWithRootViewController:cc];
    self.viewControllers=[[NSArray alloc]initWithObjects:ayNav,bNav,cNav, nil];
}

-(void)initItemsImage{
    
    UIImage *image1=[UIImage imageNamed:@"2_1"];
    UIImage *selectImage1=[UIImage imageNamed:@"2_1"];
    NSArray *imagesArray=@[image1,image1,image1];
    NSArray *selectImagesArray=@[selectImage1,selectImage1,selectImage1];
    
    NSArray *tites=@[@"aaa",@"bbb",@"ccc"];
    
    for (int i=0;i<self.tabBar.items.count;i++) {
        UITabBarItem *item=self.tabBar.items[i];
        
        item.title=tites[i];
        
        UIImage *image=imagesArray[i];
        UIImage *selectImage=selectImagesArray[i];
        
        item.image=[image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        item.selectedImage=[selectImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    }
}

-(void)initAttributes{
    NSDictionary *dic=[NSDictionary dictionaryWithObjectsAndKeys:
                       [UIColor whiteColor],
                       NSForegroundColorAttributeName,
                       nil];
    
    NSDictionary *selectDic=[NSDictionary dictionaryWithObjectsAndKeys:
                             [UIColor redColor],
                             NSForegroundColorAttributeName,
                             nil];
    
    [[UITabBarItem appearance] setTitleTextAttributes:dic forState:UIControlStateNormal];
    [[UITabBarItem appearance] setTitleTextAttributes:selectDic forState:UIControlStateSelected];
    
    UIImage* tabBarBackground = [UIImage imageNamed:@"navi_44.png"];
    [[UITabBar appearance]setBackgroundImage:tabBarBackground];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initControlles];
    [self initItemsImage];
    [self initAttributes];
    
    self.selectedIndex=0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值