如何更改所选和未选择的carbonSegmentedControl项目的alpha

时间:2017-08-18 06:12:57

标签: ios objective-c carbonkit

我尝试更改已选择和未选择的carbonSegmentedControl项目的Alpha,但无法实现该项目,而不是整个carbonSegmentedControl alpha更改。 示例代码如下:

UIButton *firstButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH/items.count-10, 43)];
firstButton.backgroundColor = [UIColor colorWithRed:0.0/255.0 green:75.0/255.0 blue:155.0/255.0 alpha:1.0];
firstButton.layer.borderWidth = 3.0;
firstButton.layer.borderColor = [UIColor whiteColor].CGColor;
[firstButton setTitle:buttonTitles[0] forState:UIControlStateNormal];
firstButton.titleLabel.font = [UIFont ProximaNova_Regular:16];


UIImage * firstButtonImage  = [self imageOfButton:firstButton];
//
UIButton *secondButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH/items.count-10, 43)];
secondButton.backgroundColor = [UIColor colorWithRed:18.0/255.0 green:209.0/255.0 blue:193.0/255.0 alpha:1.0];
secondButton.layer.borderWidth = 3.0;
secondButton.layer.borderColor = [UIColor whiteColor].CGColor;
[secondButton setTitle:buttonTitles[1] forState:UIControlStateNormal];
secondButton.titleLabel.font = [UIFont ProximaNova_Regular:16];


UIImage *secondButtonImage  = [self imageOfButton:secondButton];
//
UIButton *thirdButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH/items.count-10, 43)];
thirdButton.backgroundColor = [UIColor colorWithRed:251.0/255.0 green:252.0/255.0 blue:252.0/255.0 alpha:1.0];
thirdButton.layer.borderWidth = 3.0;
thirdButton.layer.borderColor = [UIColor colorWithRed:194.0/255.0 green:243.0/255.0 blue:237.0/255.0 alpha:1.0].CGColor;
[thirdButton setTitle:buttonTitles[2] forState:UIControlStateNormal];
thirdButton.titleLabel.font = [UIFont ProximaNova_Regular:16];
[thirdButton setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal
 ];

UIImage *thirdButtonImage  = [self imageOfButton:thirdButton];

imagesArray = [[NSArray alloc] initWithObjects:[firstButtonImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal],[secondButtonImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal],[thirdButtonImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal],nil];

carbonTabSwipeNavigation = [[CarbonTabSwipeNavigation alloc]
                            initWithItems:imagesArray
                            toolBar:_toolBar
                            delegate:self];
[carbonTabSwipeNavigation insertIntoRootViewController:self andTargetView:self.view];
carbonTabSwipeNavigation.carbonSegmentedControl.tintColor = [UIColor clearColor];

有没有完成这个? 欢迎任何相关的帮助,谢谢。

2 个答案:

答案 0 :(得分:1)

通过设置carbonSegmentedControl代理CarbobkitcarbonTabSwipeNavigation个项目的Aplha为我工作:

-(void)carbonTabSwipeNavigation:(CarbonTabSwipeNavigation *)carbonTabSwipeNavigation didMoveAtIndex:(NSUInteger)index{

    carbonTabSwipeNavigation.carbonSegmentedControl.segments[index].alpha = 1.0;

 for (NSInteger i =0; i < carbonTabSwipeNavigation.carbonSegmentedControl.segments.count; i++) {
    if(i != index)
        carbonTabSwipeNavigation.carbonSegmentedControl.segments[i].alpha = 0.5;
  }
}

答案 1 :(得分:0)

您可以使用

更改所选标签和普通标签的颜色
 [carbonTabSwipeNavigation setSelectedColor:[[UIColor whiteColor] colorWithAlphaComponent:0.6]];
 [carbonTabSwipeNavigation setNormalColor:[[UIColor greenColor] colorWithAlphaComponent:1.0]];

其中carbonTabSwipeNavigation是CarbonTabSwipeNavigation对象