gpt4 book ai didi

ios - 如何在设置按钮 alpha 的同时更改 UIButton 的 alpha

转载 作者:行者123 更新时间:2023-11-28 22:04:28 27 4
gpt4 key购买 nike

如图所示,我有 2 个具有 0.5 alpha 和 1 alpha 的按钮。我想将第一张图片中标题的 alpha 更改为 1,这可能吗?

到目前为止,我尝试了这些都不起作用:

button.titleLabel.alpha = 1;  
[button setTitleColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:1] forState:UIControlStateNormal];

enter image description here

UIButton *button = (UIButton *)view;
if(self.currentArray[index][2] != NULL) //before it was if (button == nil)
{
NSString *name = [[NSString alloc] initWithString:self.currentArray[index][2]];
UIImage *image = [UIImage imageNamed:self.currentArray[index][5]];
button = [UIButton buttonWithType:UIButtonTypeCustom];

int extraLeftInset = 0;
if ([self.currentArray[index][6] isEqualToString:@"true"]) {
//show it
}else if([self.currentArray[index][7] isEqualToString:@"true"]){

}else{
UIImage *locked = [UIImage imageNamed:@"fruitify_locked.png"];
button.imageEdgeInsets = UIEdgeInsetsMake(15, 15, 15, 15);
[button setImage:locked forState:UIControlStateNormal];
extraLeftInset = - 256; //size of locked
button.backgroundColor = [UIColor clearColor];
button.alpha = 0.5;
}

button.frame = CGRectMake(0.0, 0.0, 56, 56);
button.tag = index;

[button setBackgroundImage:image forState:UIControlStateNormal];

[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
UIEdgeInsets buttonInset = UIEdgeInsetsMake(30, -2 + extraLeftInset, -20, -2);
[button setTitleEdgeInsets:buttonInset];
[button setTitle:name forState:UIControlStateNormal];
button.titleLabel.font = [UIFont systemFontOfSize: 8];
button.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;


[button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
}

最佳答案

执行此操作的一种方法是调整图像的 alpha 值。这可以通过将图像传递给此方法来完成,

-(UIImage *)image:(UIImage *) image  withAdjustedAlpha:(CGFloat) newAlpha{
UIGraphicsBeginImageContextWithOptions(image.size, NO, 0.0);
[image drawAtPoint:CGPointZero blendMode:kCGBlendModeCopy alpha:newAlpha];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}

关于ios - 如何在设置按钮 alpha 的同时更改 UIButton 的 alpha,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24341597/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com