【UISegmentedControl】

- (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];

    //设置控件大小

    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;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值