积累系统性知识
积聚技术精华
  首页    个人中心    撰写积文    建立课题    订立目标    整理积文    管理课题    管理目标    技能Get    代码积累 
IOS-UIBarButtonItem的图片文字点击效果
error997 (error997)    2015-05-10 19:11:13      目标    课题
   Tip:为什么设置文字的某个状态时需要将其内容封装为NSDictionary?这是因为字体所关联的一系列属性,如字体风格 字体颜色等。
   设置图片等多状态的代码风格,以下是一种,常见的其他控件设置多状态一般也是以方法名set开头(以Statexxx结尾),假如只有一种状态,那么直接使用 点( . )语法设置即可。

切换到: 纯代码  
   
#pragma 处理字体点击效果   
- (void)dealWithItemFont:(UITabBarItem *)messageItem  
{  
    NSMutableDictionary *dic=[NSMutableDictionary dictionary];  
    [dic setValue:[UIColor grayColor] forKey:NSForegroundColorAttributeName];  
    [messageItem setTitleTextAttributes:dic forState:UIControlStateNormal ];  
    NSMutableDictionary *hightlineDic=[NSMutableDictionary dictionary];  
    [hightlineDic setValue:[UIColor orangeColor] forKey:NSForegroundColorAttributeName];  
    [messageItem setTitleTextAttributes:hightlineDic forState:UIControlStateHighlighted];  
}  
  
#pragma 处理图片点击效果   
- (UITabBarItem *)dealWithItemImage:(NSString *)normalImageStr selectedImageStr:(NSString *)selectedImageStr  
{  
    UIImage *normalImage=[UIImage imageNamed:normalImageStr];  
      
    UIImage *selectedImage=[UIImage imageNamed:selectedImageStr];  
    selectedImage=[selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];  
    UITabBarItem *messageItem=[[UITabBarItem alloc] init];  
    [messageItem setImage:normalImage];  
    [messageItem setSelectedImage:selectedImage];  
    return messageItem;  
}


   #pragma 处理字体点击效果
- (void)dealWithItemFont:(UITabBarItem *)messageItem
{
    NSMutableDictionary *dic=[NSMutableDictionary dictionary];
    [dic setValue:[UIColor grayColor] forKey:NSForegroundColorAttributeName];
    [messageItem setTitleTextAttributes:dic forState:UIControlStateNormal ];
    NSMutableDictionary *hightlineDic=[NSMutableDictionary dictionary];
    [hightlineDic setValue:[UIColor orangeColor] forKey:NSForegroundColorAttributeName];
    [messageItem setTitleTextAttributes:hightlineDic forState:UIControlStateHighlighted];
}

#pragma 处理图片点击效果
- (UITabBarItem *)dealWithItemImage:(NSString *)normalImageStr selectedImageStr:(NSString *)selectedImageStr
{
    UIImage *normalImage=[UIImage imageNamed:normalImageStr];
    
    UIImage *selectedImage=[UIImage imageNamed:selectedImageStr];
    selectedImage=[selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UITabBarItem *messageItem=[[UITabBarItem alloc] init];
    [messageItem setImage:normalImage];
    [messageItem setSelectedImage:selectedImage];
    return messageItem;
}

转自 http://blog.csdn.net/qq285016127/article/details/45583555
(+0)技能Get

建议楼主:搜索关键字 |参考其他资源 |回复 |追问
  error997(error997):   个人中心    课题    目标    代码积累