UISegmentedControl

  • 继承自UIControl
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]; ```

    推荐阅读