- 初始
UISegmentedControl *segment = [[UISegmentedControl alloc] initWithItems:
[NSArray arrayWithObjects: @"Mail", @”SMS”, nil]];
segment.frame = CGRectMake(10, 10, 200, 35);
segment.selectedSegmentIndex = NSIntegerMax;
segment.tag = 3;
[segment addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
segment.segmentedControlStyle = UISegmentedControlStyleBar;
[self.view addSubview:segment]; - 加入 badge, 要搭配 CustomBadge
- (IBAction) segmentAction:(id)sender
{
UISegmentedControl *segment = (UISegmentedControl*) sender;
NSLog(@"UIControlEventValueChanged:%d", segment.selectedSegmentIndex);
segment.enabled = NO;
}
- (void) viewDidLoad
{UISegmentedControl *segment = [[UISegmentedControl alloc] initWithItems:
[NSArray arrayWithObjects: @"Mail", @"SMS", nil]];
segment.frame = CGRectMake(10, 10, 200, 35);
segment.selectedSegmentIndex = NSIntegerMax;
segment.tag = 3;
[segment addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
segment.segmentedControlStyle = UISegmentedControlStyleBar;
[self.view addSubview:segment];
CustomBadge *customBadge1 = [CustomBadge customBadgeWithString:@"32"
withStringColor:[UIColor whiteColor]
withInsetColor:[UIColor greenColor]
withBadgeFrame:YES
withBadgeFrameColor:[UIColor whiteColor]
withScale:1.0
withShining:YES];
[customBadge1 setFrame:CGRectMake(90, 0, 20, 20)];
[self.view addSubview:customBadge1];
CustomBadge *customBadge2 = [CustomBadge customBadgeWithString:@"33"
withStringColor:[UIColor whiteColor]
withInsetColor:[UIColor redColor]
withBadgeFrame:YES
withBadgeFrameColor:[UIColor whiteColor]
withScale:1.0
withShining:YES];
[customBadge2 setFrame:CGRectMake(190, 0, 20, 20)];
[self.view addSubview:customBadge2];[self.view bringSubviewToFront:customBadge1];
[self.view bringSubviewToFront:customBadge2];
}
一年一度諾貝爾講座
1 週前