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

Posted

技术标签:

【中文标题】如何更改选定和未选定 carbonSegmentedControl 项目的 alpha【英文标题】:How can I change the alpha of selected and unselected carbonSegmentedControl items 【发布时间】:2017-08-18 06:12:56 【问题描述】:

我正在尝试更改已选择和未选择的 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];

有没有办法做到这一点? 欢迎任何相关帮助,谢谢。

【问题讨论】:

【参考方案1】:

通过在Carbobkit 委托carbonTabSwipeNavigation 中设置carbonSegmentedControl 项目的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;
  

【讨论】:

【参考方案2】:

您可以使用

更改选定和正常选项卡的颜色
 [carbonTabSwipeNavigation setSelectedColor:[[UIColor whiteColor] colorWithAlphaComponent:0.6]];
 [carbonTabSwipeNavigation setNormalColor:[[UIColor greenColor] colorWithAlphaComponent:1.0]];

其中 carbonTabSwipeNavigation 是 CarbonTabSwipeNavigation 对象

【讨论】:

能否请您发布您已实现的代码。 将 carbonTabSwipeNavigation 初始化更改为 carbonTabSwipeNavigation = [[CarbonTabSwipeNavigation alloc] initWithItems: imagesArray delegate:self]; carbonTabSwipeNavigation.toolbar.translucent = NO;

以上是关于如何更改选定和未选定 carbonSegmentedControl 项目的 alpha的主要内容,如果未能解决你的问题,请参考以下文章

更改选择菜单项的样式(CSS)[重复]

如何更改选定的 BottomNavigationView 图标大小

C#DataGridView修改行头字体颜色与背景颜色

我如何使用 QDialogbox 上的确定和取消按钮

在 CABasicAnimation 期间 UIButton 未显示选定状态

如何旋转图像选定行和取消旋转图像未选定行