UISegmentedControl(类似Android中的TabHost)

  //标题

    NSArray  *images=[NSArray arrayWithObjects:@"nihao",@"wohao",@"tahoa",@"helloworld", nil];

    UISegmentedControl *sc = [[UISegmentedControl alloc] initWithItems:images];

sc.segmentedControlStyle = UISegmentedControlStyleBezeled; //有四种样式可选择

sc.momentary = NO;//设置选中状态,默认是NO;

self.navigationItem.titleView = sc;

sc.frame = CGRectMake(60, 100, 200, 40); sc.selectedSegmentIndex = 1;//默认选择一个 sc.tintColor = [UIColor redColor]; [sc addTarget:self action:@selector(change:) forControlEvents:UIControlEventValueChanged]; [self.view addSubview:sc]; [sc release]; //事件方法 - (void)change:(UISegmentedControl *)sc { //角标 NSLog(@"sc : %d", sc.selectedSegmentIndex); }
 

你可能感兴趣的:(UISegmentedControl(类似Android中的TabHost))