gpt4 book ai didi

ios - UITabBarItem 在 iOS 7.1 中更改角标(Badge)颜色

转载 作者:可可西里 更新时间:2023-11-01 05:04:28 26 4
gpt4 key购买 nike

您好,我正在尝试更改 UITabBarItem 的角标(Badge)颜色。下面是我用来实现相同目的的代码。以下代码适用于 iOS 7.0。但它不适用于 iOS 7.1。感谢任何帮助。

for (UIView* tabBarButton in _tabbar.subviews) {
for (UIView* badgeView in tabBarButton.subviews) {
NSString* className = NSStringFromClass([badgeView class]);
// looking for _UIBadgeView
if ([className rangeOfString:@"BadgeView"].location != NSNotFound) {
for (UIView* badgeSubview in badgeView.subviews) {
NSString* className = NSStringFromClass([badgeSubview class]);

// looking for _UIBadgeBackground
if ([className rangeOfString:@"BadgeBackground"].location != NSNotFound) {
@try {
NSLog(@"*******************BADGE IMAGE SET *******************");
[badgeSubview setValue:[UIImage imageNamed:@"count_bg.png"] forKey:@"image"];
//[badgeSubview setTintColor:[UIColor greenColor]];
}
@catch (NSException *exception) {}
}

if ([badgeSubview isKindOfClass:[UILabel class]]) {
((UILabel *)badgeSubview).textColor = [UIColor whiteColor];
}
}
}
}
}

最佳答案

最后,我向 tabBar 添加了一个具有所需颜色的标签,并获得了预期的结果。

    UILabel *badge=[[UILabel alloc]init];
badge.text = @"2";
badge.textAlignment=NSTextAlignmentCenter;
badge.frame=CGRectMake(122, 1, 20, 20);
badge.layer.cornerRadius=10;
badge.textColor=[UIColor whiteColor];
badge.backgroundColor=[UIColor greenColor];
[tabbar addSubview:badge];

关于ios - UITabBarItem 在 iOS 7.1 中更改角标(Badge)颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23028926/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com