【UISlider滑动控件】

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/winer888/article/details/48030705

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

    self.window=[[UIWindowalloc]initWithFrame:[[UIScreenmainScreen]bounds]];

    self.window.backgroundColor=[UIColorwhiteColor];

    UIViewController *v=[[UIViewControlleralloc]init];

    self.window.rootViewController=v;

    [self.windowmakeKeyAndVisible];

    //创建数组,内容是分段控件的各分区标题

    NSArray *ns=[[NSArrayalloc]initWithObjects:@"enter",@"come",@"system",nil];

    //创建分段控件

    UISegmentedControl *segment=[[UISegmentedControlalloc]initWithItems:ns];

扫描二维码关注公众号,回复: 4947840 查看本文章

    //设置控件大小

    segment.frame=CGRectMake(30,4020050);

    //初始选中第一位置的区

    [segment setSelectedSegmentIndex:1];

    //给控件设置目标事件

    [segment addTarget:selfaction:@selector(visibel:)forControlEvents:UIControlEventValueChanged];

    

    //创建标签及大小

    label=[[UILabelalloc]initWithFrame:CGRectMake(250,407050)];

    label.backgroundColor=[UIColorgreenColor];

    

    [self.windowaddSubview:segment];

    [self.windowaddSubview:label];

    

    

    //UIViewController *v=[[UIViewController alloc]init];

    

    return YES;

}

-(void)visibel:(UISegmentedControl *)sender

{

    //测试控件各分区的索引位置

    NSLog(@"%d",(int)[senderselectedSegmentIndex]);

    //让标签显示的文本等于当前选中的控件分区标题

    label.text=[sendertitleForSegmentAtIndex:[sender selectedSegmentIndex]];

    //文本方向置中

    label.textAlignment=NSTextAlignmentCenter;

}

猜你喜欢

转载自blog.csdn.net/winer888/article/details/48030705