【问题标题】:iOS, UIBarButtonItem: Custom label bound to UIBarButtonItemiOS,UIBarButtonItem:自定义标签绑定到 UIBarButtonItem
【发布时间】:2014-11-12 17:57:25
【问题描述】:

我在将自定义标签附加到我的 UIBarButtonItem 时遇到问题。我的代码:

UILabel *lbl=[[UILabel alloc]initWithFrame:CGRectMake(0.00, 0.00, 10.0, 10.0)];
        lbl.font=[UIFont fontWithName:@"Verdana" size:7];
        lbl.textAlignment=NSTextAlignmentCenter;
        lbl.textColor=[UIColor darkGrayColor];
        lbl.text=@"Subtypes available:";
        lbl.backgroundColor=[UIColor lightGrayColor];

        _btnSubtypes.enabled=YES; // UIBarButtonItem
        _btnSubtypes.title=[NSString stringWithFormat:@"%lu / %lu",[_ucqc returnQuantityOfListedSubtypes:_coin],[_ucqc returnPureQuantityOfSubtypesInType:_coin]];
        [_btnSubtypes setAction:@selector(navigateToSubtypes)];
        [_btnSubtypes.customView addSubview:lbl];

此代码在viewWillAppear 方法中执行。所以,它没有设置标签。它有什么问题?

提前谢谢你。

【问题讨论】:

    标签: ios cocoa-touch uibarbuttonitem


    【解决方案1】:

    嗨,我认为自定义使用 UIButton 比 UIBarButtonItem 更好。在您的代码中,您没有任何 customView。如果你插入一个 NSLog 语句,你可以看到不是 nil。

    [_btnSubtypes.customView addSubview:lbl];
    NSLog(@"have I go customView? %@",[_btnSubtypes.customView description]);
    

    你应该改变这个:

      _btnSubtypes.customView=lbl;
    

    但结果可能与您的预期不符。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-11
      • 2012-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-27
      相关资源
      最近更新 更多