分段控件segmentedControl

吉和同
2023-12-01

//分段控件UISegmentedControl

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    NSArray *segments = @[@"RIGHT",@"LEFT"];
    UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:segments];
    CGFloat segmentsW = 200;
    CGFloat segmentsH = 100;
    CGFloat segmentsX = 100;
    CGFloat segmentsY = 100;
    CGRect frame = CGRectMake(segmentsX, segmentsY, segmentsW, segmentsH);
    segmentedControl.frame = frame;
    [segmentedControl addTarget:self action:@selector(touchDown:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:segmentedControl];
}
-(void)touchDown:(id)sender{
    //UISegmentedControl的方法
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end

 

 类似资料: