右侧栏按钮项目上徽章的稳定位置

时间:2013-03-11 16:38:56

标签: ios objective-c orientation uibarbuttonitem

我的应用在右侧栏按钮项custom badge上有徽章,当方向更改徽章转到导航栏的中间时

肖像

enter image description here

景观:

enter image description here

-(void)viewDidAppear:(BOOL)animated
{
    _customBadge1 = [CustomBadge customBadgeWithString:@"2"
                                       withStringColor:[UIColor whiteColor]
                                        withInsetColor:[UIColor redColor]
                                        withBadgeFrame:YES
                                   withBadgeFrameColor:[UIColor whiteColor]
                                             withScale:1.0
                                           withShining:YES];

    // Set Position of Badge
    CGRect frameimgback2 = CGRectMake(742, 0, 20, 20);
    _customBadge1.frame=frameimgback2;
    [self.navigationController.navigationBar addSubview:_customBadge1];

}

如何稳定此徽章始终保持在同一位置(右侧栏按钮右上方)?

谢谢,

1 个答案:

答案 0 :(得分:1)

尝试

_customBadge1.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin |
               UIViewAutoresizingFlexibleTopMargin);