UISegmentedControl (待续)

- (void)viewDidLoad{

    ........
    ........
    //创建
    UISegmentedControl *segmentC = [[UISegmentedControl alloc]initWithFrame:(CGRect){0,0,200,25}];
    segmentC.tintColor = [UIColor colorWithRed:146/255.0 green:25/255.0 blue:24/255.0 alpha:1];
    
    [segmentC insertSegmentWithTitle:@"  私信  " atIndex:0 animated:NO];
    [segmentC insertSegmentWithTitle:@"系统通知" atIndex:1 animated:NO];
    //默认选中0
    segmentC.selectedSegmentIndex = 0;
    
    //添加响应时间
    [segmentC addTarget:self action:@selector(changeMessage:) forControlEvents:UIControlEventValueChanged];
    
    //放到导航中间
    self.navigationItem.titleView = segmentC;

}

//响应 判断索引值
- (void)changeMessage:(UISegmentedControl *)sender{

    if(sender.selectedSegmentIndex == 0){
        NSLog(@"私信");
    }else{
        NSLog(@"系统通知");
    }

}


效果:

UISegmentedControl (待续)_第1张图片



更多参数待续……

你可能感兴趣的:(UISegmentedControl (待续))