UISegmentedControl(相似Android中的TabHost)

//標題

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

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

sc.segmentedControlStyle = UISegmentedControlStyleBezeled; //有四種樣式可選擇 spa

sc.momentary = NO;//設置選中狀態,默認是NO; code

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); }
 
相關文章
相關標籤/搜索