UISegmentControl样式设置

来源:互联网 发布:我国加工贸易知乎 编辑:程序博客网 时间:2024/06/05 13:23

设置选中未选中时的效果,很简单,一目了然

    NSArray *array = @[@"第一组",@"第二组"];    segmentC = [[UISegmentedControl alloc]initWithItems:array];    [segmentC addTarget:self action:@selector(change:) forControlEvents:UIControlEventValueChanged];    segmentC.tintColor = [UIColor clearColor];    NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"Heiti SC" size:13],NSFontAttributeName,[UIColor lightGrayColor], NSForegroundColorAttributeName, nil];    [segmentC setTitleTextAttributes:attributes forState:UIControlStateNormal];    NSDictionary *highlightedAttributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"Heiti SC" size:15],NSFontAttributeName,backTextColor, NSForegroundColorAttributeName, nil];    [segmentC setTitleTextAttributes:highlightedAttributes forState:UIControlStateSelected];    segmentC.selectedSegmentIndex = 0;    [self.view addSubview:segmentC];
0 0