UISegmentedControl的應用舉例
//生成選項按鈕
UISegmentedControl *seg = [[UISegmentedControl alloc]initWithItems:@[@"足球",@"籃球"]];
//設置正常背景圖片
[seg setBackgroundImage:[UIImage imageNamed:@"CPArenaSegmentBG"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
//設置選中背景圖片
[seg setBackgroundImage:[UIImage imageNamed:@"CPArenaSegmentSelectedBG"] forState:UIControlStateSelected barMetrics:UIBarMetricsDefault];
//默認選中第一個按鈕
seg.selectedSegmentIndex = 0;
//設置主題顏色
seg.tintColor = [UIColor colorWithRed:0 green:142 blue:143 alpha:1];
//設置選中時文字顏色
[seg setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]} forState:UIControlStateSelected];
```