我想在我的UISegements上设置数字徽章,所以我尝试了MESegmentedControl,但徽章会出现在错误的位置,(索引0的徽章会出现在索引1处)不确定是否由于自动布局或其他什么,所以相反我 我为每个细分添加了Custom Badge,除了高光颜色有时会覆盖徽章外,它的工作效果很好。我试过带来ToFront,但这并没有帮助。有什么我可以打电话来解决这个问题吗?谢谢你的帮助!
我的代码在viewWillAppear中创建徽章:
- (void)viewWillAppear:(BOOL)animated
{
CGFloat totalW = self.view.bounds.size.width;
JSCustomBadge *badgeALL = [JSCustomBadge customBadgeWithString:@"1"];
JSCustomBadge *badgeCA = [JSCustomBadge customBadgeWithString:@"2"];
JSCustomBadge *badgeOR = [JSCustomBadge customBadgeWithString:@"3"];
JSCustomBadge *badgeNV = [JSCustomBadge customBadgeWithString:@"4"];
NSMutableArray *badges = [NSMutableArray arrayWithObjects:
badgeALL, badgeKLN, badgeNT, badgeHK,nil];
CGFloat y = 0.0f;
CGFloat thisW = 23.0f;
CGFloat thisH = 23.0f;
badgeALL.frame = CGRectMake(totalW*0.15, y, thisW,thisH);
badgeCA.frame = CGRectMake(totalW*0.375, y, thisW,thisH);
badgeOR.frame = CGRectMake(totalW*0.6, y, thisW,thisH);
badgeNV.frame = CGRectMake(totalW*0.83, y, thisW,thisH);
for (JSCustomBadge *each in badges) {
[_districtsSegCtrl addSubview:each];
[_districtsSegCtrl bringSubviewToFront:each];
}
};