在 a 中有UISegmentedControl
一个navigationBar
,它在 the 中创建Storyboard
并且有一个Outlet
连接到它。我曾尝试向 中添加自定义徽章UISegmentedControl
,但失败了。徽章不出现。
附言。当我将自定义徽章添加到navigationBar
(的超级视图UISegmentedControl
)时,会出现自定义徽章,但它是我的第二种方法。我想直接添加到UISegmentedControl
,可以吗?
MyTableViewController.h
...
@interface MyTableViewController : UITableViewController{
}
@property (strong,nonatomic) IBOutlet UISegmentedControl *segmentedControl;
...
MyTableViewController.m
@synthesize segmentedControl;
...
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
CustomBadge *customBadge = [CustomBadge customBadgeWithString:@"1" withStringColor:[UIColor whiteColor] withInsetColor:[UIColor orangeColor] withBadgeFrame:YES withBadgeFrameColor:[UIColor whiteColor] withScale:0.8 withShining:YES];
NSLog(@"self.segmentedControl :%@",self.segmentedControl);
NSLog(@"self.segmentedControl w: %f, h :%f",self.segmentedControle.frame.size.width, self.segmentedControlle.frame.size.height);
NSLog(@"customBadge x: %f, y: %f, w: %f, h :%f", customBadge.frame.origin.x, customBadge.frame.origin.y,customBadge.frame.size.width, customBadge.frame.size.height);
[self.segmentedControl addSubview:customBadge];
}
...
日志结果:
self.segmentedControl :<UISegmentedControl: 0x3b7bf0; frame = (83 7; 154 30); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x3b7c70>>
self.segmentedControl w: 154.000000, h :30.000000
customBadge x: 0.000000, y: 0.000000, w: 20.000000, h :20.000000
这CustomBadge
是第三方自定义徽章视图类。