我正在使用最新的SDK和Xcode 4.2开发iOS 4应用程序。
我在AppDelegate上以编程方式添加了UINavigationController,并将其设置为黑色。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
viewController.title = @"Menu";
navController = [[UINavigationController alloc] initWithRootViewController:viewController];
navController.navigationBar.tintColor = [UIColor blackColor];
self.window.rootViewController = navController;
[self.window makeKeyAndVisible];
return YES;
}
在一个视图控制器上,我添加了一个UISegmentedControl:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
// Do any additional setup after loading the view from its nib.
segmentedControl = [[UISegmentedControl alloc] initWithItems:
[NSArray arrayWithObjects:
[NSString stringWithString:@"Past"],
[NSString stringWithString:@"Present"],
[NSString stringWithString:@"Future"],
nil]];
[segmentedControl addTarget:self action:@selector(segmentedChanged:) forControlEvents:UIControlEventValueChanged];
segmentedControl.frame = CGRectMake(0, 0, 260, 30);
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControl.selectedSegmentIndex = 0;
self.navigationItem.titleView = segmentedControl;
}
但是,当我选择一个项目时,我可以看到它,因为它是黑色的。
当选择某个项目时,是否还要设置为其他颜色?
答案 0 :(得分:0)
尝试使用segmentedControlIndexChanged
,然后使用self.segmentedControl.selectedSegmentIndex
检测选择了哪一个并更改了这些段颜色。