[ 登录注册 ]

ios

iPhone之UISegmentedControl开发

2016/08/11 11:19 [db:作者] 返回上一页

代码:
    //选择按钮
    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”
 

点击复制链接 与好友分享!回本站首页

文章来源:http://www.bozhiyue.com/ios/2016/0811/364076.html
评论
发表评论