Skip to content

Instantly share code, notes, and snippets.

@lloydsheng
Last active March 19, 2018 08:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lloydsheng/6459429 to your computer and use it in GitHub Desktop.
Save lloydsheng/6459429 to your computer and use it in GitHub Desktop.
一端iOS5.0以上订制UITabbar的代码
[self.tabBar setSelectionIndicatorImage:[UIImage imageNamed:@"tab-bar_highlighted.png"]];
[[UITabBarItem appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
RGB(187, 187, 187), UITextAttributeTextColor,
[UIFont systemFontOfSize:10], UITextAttributeFont,
nil]
forState:UIControlStateNormal];
[[UITabBarItem appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
RGB(153, 210, 249), UITextAttributeTextColor,
[UIFont systemFontOfSize:10], UITextAttributeFont,
nil]
forState:UIControlStateSelected];
[self.tabBar setBackgroundImage:[UIImage imageNamed:@"tab-bar.png"]];
for (NSInteger i = 0; i < self.tabBar.items.count; i++) {
UITabBarItem *item = [self.tabBar.items objectAtIndex:i];
[item setTitle:[titles objectAtIndex:i]];
item.titlePositionAdjustment = UIOffsetMake(1, -2);
[item setFinishedSelectedImage:[UIImage imageNamed:[selectedImageNames objectAtIndex:i]]
withFinishedUnselectedImage:[UIImage imageNamed:[imageNames objectAtIndex:i]]
];
[item setImageInsets:UIEdgeInsetsMake(1 -1, 0, -1 + 1, 0)];
}
UIImageView *view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
view.backgroundColor = [UIColor redColor];
[self.tabBar addSubview:view];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment