当前位置:编程学习 > wap >>

iPhone之UISegmentedControl开发

代码:
    //选择按钮
    NSArray *buttonNames = [NSArray arrayWithObjects:@"今天", @"本周", @"本月", nil];
    UISegmentedControl* segmentedControl = [[UISegmentedControl alloc] initWithItems:buttonNames];
    [segmentedControl setFrame:CGRectMake(60, 10, 200, 40)];
    segmentedControl.selectedSegmentIndex=1;
    //添加事件
    [segmentedControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:segmentedControl];
    [segmentedControl release];

    //事件

-(void)segmentAction:(UISegmentedControl *)Seg{
    NSInteger Index = Seg.selectedSegmentIndex;
    NSLog(@"Seg.selectedSegmentIndex:%d",Index);
}

作者“cissco”
 

补充:移动开发 , IOS ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,