SegmentedControl 的创建以及自定义

孔弘盛
2023-12-01


   

- (void)viewDidLoad {

    [super viewDidLoad];

    

    NSArray *segmentedArray = [[NSArray alloc]initWithObjects:@"推荐",@"最新",nil];

    

    //初始化UISegmentedControl

    

    UISegmentedControl *segmentedControl = [[UISegmentedControl alloc]initWithItems:segmentedArray];

    

    segmentedControl.frame = CGRectMake(157,20,100,40);

    

     //设置默认选择项索引

    segmentedControl.selectedSegmentIndex = 2;

    

    segmentedControl.tintColor = [UIColor  whiteColor];

    

    [self.view addSubview:segmentedControl];

}

 类似资料: