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; }
时间: 2024-10-25 04:17:49