#import "ViewController.h" @interface ViewController () { UISegmentedControl *sc; } @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. sc = [[UISegmentedControl alloc] initWithItems:@[@"11123123123",@"22",@"33",@"44"]]; sc.frame = CGRectMake(10,20,300,30); [self.view addSubview:sc]; //Short-lived //sc.momentary = YES; sc.apportionsSegmentWidthsByContent = YES; //NSLog(@"%d",sc.numberOfSegments); //[sc setContentOffset:CGSizeMake(10,10) forSegmentAtIndex:1]; [sc setEnabled:NO forSegmentAtIndex:1]; sc.selectedSegmentIndex = 1; //font border color includes background color sc.tintColor = [UIColor redColor]; [sc setDividerImage:[UIImage imageNamed:@"22.jpg"] forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; } - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { //[sc insertSegmentWithTitle:@"Insert button" atIndex:1 animated:YES]; //[sc insertSegmentWithImage:[[UIImage imageNamed:@"11.jpg"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]atIndex:0 animated:YES]; //[sc removeSegmentAtIndex:0 animated:YES]; //[sc removeAllSegments]; //[sc setTitle:@"i'm retitle" forSegmentAtIndex:1]; [sc setWidth: 100 forSegmentAtIndex: 1]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
UISegmentedControl
Guess you like
Origin http://10.200.1.11:23101/article/api/json?id=326670109&siteId=291194637
Recommended
Ranking