diff --git a/Sample App/iPhoneMK Sample App/NumberBadgeViewController.h b/Sample App/iPhoneMK Sample App/NumberBadgeViewController.h index a941ab2..3a081cc 100644 --- a/Sample App/iPhoneMK Sample App/NumberBadgeViewController.h +++ b/Sample App/iPhoneMK Sample App/NumberBadgeViewController.h @@ -27,6 +27,7 @@ @property (retain, nonatomic) IBOutlet UIToolbar* myToolbar; @property (retain, nonatomic) MKNumberBadgeView* badgeSeven; @property (retain, nonatomic) MKNumberBadgeView* badgeEight; +@property (retain, nonatomic) MKNumberBadgeView* badgeNine; -(IBAction)slideValueChanged:(id)sender; diff --git a/Sample App/iPhoneMK Sample App/NumberBadgeViewController.m b/Sample App/iPhoneMK Sample App/NumberBadgeViewController.m index 4af4bd5..8809638 100644 --- a/Sample App/iPhoneMK Sample App/NumberBadgeViewController.m +++ b/Sample App/iPhoneMK Sample App/NumberBadgeViewController.m @@ -69,33 +69,57 @@ - (void)viewDidLoad // Badge Seven UIButton* buttonSeven = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 70, 30)]; - buttonSeven.titleLabel.text = @"seven"; [buttonSeven setTitle:@"seven" forState:UIControlStateNormal]; [buttonSeven setBackgroundColor:[UIColor blueColor]]; self.badgeSeven = [[MKNumberBadgeView alloc] initWithFrame:CGRectMake(buttonSeven.frame.size.width - 37, -15, 74, 30)]; + self.badgeSeven.font = [UIFont boldSystemFontOfSize:11]; [buttonSeven addSubview:self.badgeSeven]; - // Badge Eight + // Badge Eight - Wrong way self.badgeEight = [[MKNumberBadgeView alloc] initWithFrame:CGRectMake(-22, -15, 44, 30)]; - UISegmentedControl* segmentedControl = - [[UISegmentedControl alloc] initWithItems:@[@"9a",@"9b", @"9c"]]; - [segmentedControl addSubview:self.badgeEight]; - - // Add buttons seven and eight to the toolbar - UIBarButtonItem* buttonEight = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl]; + self.badgeEight.font = [UIFont boldSystemFontOfSize:11]; + UISegmentedControl* segmentedControlEight = + [[UISegmentedControl alloc] initWithItems:@[@"9a",@"9b",@"9c"]]; + segmentedControlEight.segmentedControlStyle = UISegmentedControlStyleBar; + segmentedControlEight.momentary = YES; + [segmentedControlEight addSubview:self.badgeEight]; + UIBarButtonItem* buttonEight = [[UIBarButtonItem alloc] initWithCustomView:segmentedControlEight]; + + // Badge Nine - Right Way + self.badgeNine = [[MKNumberBadgeView alloc] initWithFrame:CGRectMake(-22, + -15, + 44, + 30)]; + self.badgeNine.font = [UIFont boldSystemFontOfSize:11]; + UISegmentedControl* segmentedControlNine = + [[UISegmentedControl alloc] initWithItems:@[@"9a",@"9b",@"9c"]]; + segmentedControlNine.segmentedControlStyle = UISegmentedControlStyleBar; + segmentedControlNine.momentary = YES; + //segmentedControlNine.tintColor = [UIColor blackColor]; // may need to be set explicitly because of container indirection + UIView* containerViewNine = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 90, 30)]; + [containerViewNine addSubview:segmentedControlNine]; + [containerViewNine addSubview:self.badgeNine]; + UIBarButtonItem* buttonNine = [[UIBarButtonItem alloc] initWithCustomView:containerViewNine]; + + // Add seven, eight and nine to the toolbar + NSArray* toobarItems = @[ [[UIBarButtonItem alloc] initWithCustomView:buttonSeven], [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil], - buttonEight + buttonEight, + [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace + target:nil + action:nil], + buttonNine ]; [self.myToolbar setItems:toobarItems]; @@ -152,6 +176,7 @@ -(IBAction)slideValueChanged:(id)sender { self.badgeSix.value = sliderValue * 1000; self.badgeSeven.value = sliderValue * 1000; self.badgeEight.value = sliderValue; + self.badgeNine.value = sliderValue; } @end