大佬教程收集整理的这篇文章主要介绍了objective-c – UITabbarItem BadgeValue文本颜色,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
> http://www.luventas-webdesign.de/stackoverflow/screenshot_badgevalue.png
>就像颜色在我的应用程序中
>
> http://www.luventas-webdesign.de/stackoverflow/screenshot_like_it_should.png
>喜欢的颜色通常应该是……
>
编辑02.11.2012 – 代码
创建TabBarController:
#import "ExtendedTabBarController.h" #import "configuration.h" @implementation ExtendedTabBarController - (void)viewDidLoad { [super viewDidLoad]; [[UITabBarItem appearance] settitleTextAttributes:[NSDictionary DictionaryWithObjectsAndKeys: [UIColor colorWithRed:207.0/255.0 green:70.0/255.0 blue:61.0/255.0 alpha:1],UITextAttributeTextColor,[UIFont fontWithName:@"KievitPro-Regular" size:10.0],UITextAttributeFont,nil] forState:UIControlStateSELEcted]; [[UITabBarItem appearance] settitleTextAttributes:[NSDictionary DictionaryWithObjectsAndKeys: [UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1],nil] forState:UIControlStateNormal]; [self.tabBar sizeToFit]; UIView *tabbarBACkgroundColorView = [[UIView alloc] initWithFrame:CGRectMake(0.0,self.view.bounds.size.width,49)]; [tabbarBACkgroundColorView setBACkgroundColor:[UIColor colorWithRed:233.0/255.0 green:233.0/255.0 blue:233.0/255.0 alpha:1]]; [self.tabBar insertSubview:tabbarBACkgroundColorView aTindex:0]; } - (void)viewDidUnload { [super viewDidUnload]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return UIInterfaceOrientationIsPor@R_673_9829@t(interfaceOrientation); // only por@R_673_9829@t orientation } /** * orientation for iOS6 **/ -(NSUInteger)supportedInterfaceOrientations{ return UIInterfaceOrientationMaskPor@R_673_9829@t; } @end
在AppDelegate中调用:
ExtendedTabBarController *tabBarController = [[ExtendedTabBarController alloc] init]; [self setTabBarController:tabBarController]; [[UITabBar appearance] setBACkgroundImage:[UIImage imagenamed:@"menu_bg"]]; // code for initialize View- and NavigationControllers... self.tabBarController.viewControllers = @[highlightsNavigationController,categoryNavigationController,searchNavigationController,favoritesNavigationController,imprintNavigationController]; self.window.rootViewController = self.tabBarController; [[UITabBar appearance] setSELEctionInDicatorImage:[[UIImage alloc] init]];
设置徽章值:
int viewCount = 0; NSUserDefaults * defs = [NSUserDefaults standardUserDefaults]; NSDictionary * Dict = [defs DictionaryRepresentation]; for (id key in Dict) { if([key rangeOfString:@"_highlighted"].LOCATIOn != NsnotFound && [[[Dict objectForKey:key] objectATindex:0] isEqualToString:@"YES"]) { viewCount++; } } UITabBarItem *tbi = (UITabBarItem *)[self.tabBarController.tabBar.items objectATindex:3]; if(viewCount <= 0) { tbi.badgeValue = nil; } else { tbi.badgeValue = nil; tbi.badgeValue = [NSString StringWithFormat:@"%d",viewCount]; }
覆盖UILabel的代码:
// -- file: UILabel+VerticalAlign.h #pragma mark VerticalAlign @interface UILabel (VerticalAlign) - (void)alignTop; - (void)alignBottom; - (void)awakeFromNib; -(id)initWithFrame:(CGRect)frame; @end #import "UILabel+VerticalAlign.h" // -- file: UILabel+VerticalAlign.m @implementation UILabel (VerticalAlign) - (void)alignTop { CGSize fontSize = [self.text sizeWithFont:self.font]; double finalHeight = fontSize.height * self.numberOfLines; double finalWidth = self.frame.size.width; //expected width of label CGSize theStringSize = [self.text sizeWithFont:self.font cons@R_673_9829@nedToSize:CGSizeMake(finalWidth,finalHeight) lineBreakmode:self.lineBreakmode]; int newLinesToPad = (finalHeight - theStringSize.height) / fontSize.height; for(int i=0; i<newLinesToPad; i++) self.text = [self.text StringByAppendingString:@"\n "]; } - (void)alignBottom { CGSize fontSize = [self.text sizeWithFont:self.font]; double finalHeight = fontSize.height * self.numberOfLines; double finalWidth = self.frame.size.width; //expected width of label CGSize theStringSize = [self.text sizeWithFont:self.font cons@R_673_9829@nedToSize:CGSizeMake(finalWidth,finalHeight) lineBreakmode:self.lineBreakmode]; int newLinesToPad = (finalHeight - theStringSize.height) / fontSize.height; for(int i=0; i<newLinesToPad; i++) self.text = [NSString StringWithFormat:@" \n%@",self.text]; } - (void)awakeFromNib { [super awakeFromNib]; [self setFont:[UIFont fontWithName:@"KievitPro-Regular" size:12.0]]; } -(id)initWithFrame:(CGRect)frame { id result = [super initWithFrame:frame]; if (result) { [self setFont:[UIFont fontWithName:@"KievitPro-Regular" size:12.0]]; } return result; } @end
我必须从覆盖的UILabel中删除以下行:
- (void)awakeFromNib { [super awakeFromNib]; [self setFont:[UIFont fontWithName:@"KievitPro-Regular" size:12.0]]; } -(id)initWithFrame:(CGRect)frame { id result = [super initWithFrame:frame]; if (result) { [self setFont:[UIFont fontWithName:@"KievitPro-Regular" size:12.0]]; } return result; }
以上是大佬教程为你收集整理的objective-c – UITabbarItem BadgeValue文本颜色全部内容,希望文章能够帮你解决objective-c – UITabbarItem BadgeValue文本颜色所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。