gpt4 book ai didi

iOS 更改动态 UIActionsheet 按钮的颜色

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

我制作了如下动态 uiactionsheet:

- (IBAction)selectCity
{
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:kCityActionSheetTitle
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
for (NSString * cityNameNSS in [_cityNamesAndUrlsNSMD allKeys]) {
[actionSheet addButtonWithTitle:cityNameNSS];
}
[actionSheet addButtonWithTitle:kCancellButtonTitle];
actionSheet.cancelButtonIndex = [[_cityNamesAndUrlsNSMD allKeys] count];
actionSheet.tag = 2;
[actionSheet showInView:[UIApplication sharedApplication].keyWindow];

}

我想更改 uiactionsheet 按钮的色调。因此我写道:

- (void)willPresentActionSheet:(UIActionSheet *)actionSheet
{
for (UIView *subview in actionSheet.subviews) {

if ([subview isKindOfClass:[UIButton class]]) {
UIButton *button = (UIButton *)subview;
[button setTitleColor:[UIColor colorWithRed:0.0/255.0 green:150.0/255.0 blue:94.0/255.0 alpha:1.0]
forState:UIControlStateNormal];
}
else if([subview isKindOfClass:[UILabel class]]){
UILabel *label = (UILabel *)subview;
[label setTextColor:[UIColor colorWithRed:0.0/255.0 green:150.0/255.0 blue:94.0/255.0 alpha:1.0]];

}
}
}

但是,只有在这种情况下(在动态 uiactionsheet 中),按钮颜色不会改变。我在同一个 Controller 中有其他 uiactionssheet,它们正在改变颜色。

可能的问题/解决方案是什么?

最佳答案

请为您的按钮添加标签

 - (void)willPresentActionSheet:(UIActionSheet *)actionSheet
{
for (UIView *subview in actionSheet.subviews)
{
if ([subview isKindOfClass:[UIButton class]])
{
if (subview.tag == 3)
{
NSLog(@"ButtonIndex===%d",subview.tag);
UIButton *button = (UIButton *)subview;
[button setTitleColor:[UIColor colorWithRed:0.0/255.0 green:150.0/255.0 blue:94.0/255.0 alpha:1.0]
forState:UIControlStateNormal];


}
}
}
}

关于iOS 更改动态 UIActionsheet 按钮的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23292115/

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