zoukankan      html  css  js  c++  java
  • UI控件(UISegmentedControl)

    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        
        NSArray* segmentArray = [[NSArray alloc]initWithObjects:@"Title1", @"Title2", @"Title3",nil];
        
        //也可以通过insertSegmentWithtitile方法添加选项
        //也可以对某个选项选择添加图片
        UISegmentedControl* segmentedControl = [[UISegmentedControl alloc]initWithItems:segmentArray];
        segmentedControl.frame = CGRectMake(30, 20, 250, 30);
        
        //设置选项卡的默认点击项,从索引0开始
        segmentedControl.selectedSegmentIndex = 0;
        
        //分段选项卡的颜色,默认为蓝色
        segmentedControl.tintColor = [UIColor redColor];
        
        //设置选项卡在点击后是否会恢复原状
        segmentedControl.momentary = NO;
        
        //segmentedControlStyle 在IOS 7以后无效
        //segmentedControl.segmentedControlStyle = UISegmentedControlStyleBezeled;
        
        //添加选项卡选择事件
        [segmentedControl addTarget:self action:@selector(doSelected:) forControlEvents:UIControlEventValueChanged];
        
        [self.view addSubview:segmentedControl];
        
    }
    
    -(void)doSelected:(id)sender{
        UISegmentedControl* tmp = (UISegmentedControl*)sender;
        NSLog(@"%ld", tmp.selectedSegmentIndex);
    }
    
    @end
  • 相关阅读:
    python 不可变类型
    python 不定长参数
    Codeforces Round #749
    [提高组集训2021] Round1
    AtCoder Regular Contest 128
    [提高组互测] Day6
    [提高组互测] Day5
    [提高组互测] Day1
    [提高组互测] Day2
    [提高组集训2021] 一拳超人
  • 原文地址:https://www.cnblogs.com/Fredric-2013/p/5186310.html
Copyright © 2011-2022 走看看