ios - 标签的 UIButton 文本不可见

标签 ios objective-c iphone uibutton accessibility

问题:如果用户在 iPhone/iPad 上转到“设置 - 通用 - 辅助功能 - 增加对比度”并打开“加深颜色”,我的按钮上的文字就会消失。

这是我创建按钮的代码:

buttonCurrent = [UIButton buttonWithType:UIButtonTypeSystem];
buttonCurrent.translatesAutoresizingMaskIntoConstraints = NO;
buttonCurrent.titleLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
buttonCurrent.titleLabel.textAlignment = NSTextAlignmentCenter;
buttonCurrent.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
buttonCurrent.titleLabel.numberOfLines = 2;
buttonCurrent.titleEdgeInsets = UIEdgeInsetsMake(0, 5, 0, 5);
buttonCurrent.backgroundColor = [UIColor whiteColor];
[buttonCurrent setTitle:NSLocalizedString(@"Add the reading with the current date", nil) forState:UIControlStateNormal];
[buttonCurrent addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];

感谢您的帮助。 我将代码更改为:

buttonCurrent = [UIButton buttonWithType:UIButtonTypeCustom];
buttonCurrent.translatesAutoresizingMaskIntoConstraints = NO;
buttonCurrent.titleLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
[buttonCurrent setTitleColor:self.view.tintColor forState:UIControlStateNormal];
[buttonCurrent setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];
[buttonCurrent setTitleColor:[UIColor lightGrayColor] forState:UIControlStateDisabled];
buttonCurrent.titleLabel.textAlignment = NSTextAlignmentCenter;
buttonCurrent.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
buttonCurrent.titleLabel.numberOfLines = 2;
buttonCurrent.titleEdgeInsets = UIEdgeInsetsMake(0, 5, 0, 5);
buttonCurrent.backgroundColor = [UIColor grayColor];
[buttonCurrent setTitle:NSLocalizedString(@"Add the reading with the current date", nil) forState:UIControlStateNormal];

它现在看起来像 UIButtonTypeSystem,它也适用于系统设置“Darken Colors”。

最佳答案

除了第一行,所有代码都很好。

buttonCurrent = [UIButton buttonWithType:UIButtonTypeCustom];

UIButtonTypeSystem have default blue color as a back ground in greater than iOS7. You should always use UIButtonTypeCustom, so that it does not shows the effect as you are experience.

也请给框架。我检查了你的代码,你没有给出按钮的框架。请先这样做。

UIButton *buttonCurrent = [UIButton buttonWithType:UIButtonTypeCustom];
buttonCurrent.translatesAutoresizingMaskIntoConstraints = NO;
buttonCurrent.titleLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
buttonCurrent.titleLabel.textAlignment = NSTextAlignmentCenter;
buttonCurrent.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
buttonCurrent.titleLabel.numberOfLines = 2;
buttonCurrent.titleEdgeInsets = UIEdgeInsetsMake(0, 5, 0, 5);
buttonCurrent.backgroundColor = [UIColor whiteColor];
buttonCurrent.frame = CGRectMake(0, 50, 320, 80);
[buttonCurrent setTitleColor:[UIColor colorWithRed:0.0 green:0.5 blue:1.0 alpha:1.0] forState:UIControlStateNormal];
[buttonCurrent setTitle:@"Add the reading with the current date" forState:UIControlStateNormal];
[buttonCurrent addTarget:self action:@selector(back:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:buttonCurrent];

关于ios - 标签的 UIButton 文本不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28189891/

相关文章:

ios - awakeFromNib 中的 @IBOutlet 未初始化

ios - 使用自签名根证书的 SSLHandshake 失败 (-9808)

ios - iOS 8.0 升级后 UILabel 不显示

objective-c - 用于按组选择具有最大值的行的 NSPredicate

ios - 当应用程序在后台时,如何继续收听来自 googlecast 的事件?

ios - 自更新到 iOS 6 后的可达性问题

objective-c - 进入背景时,iOS拍摄快照的确切时间?

ios - 将 UIImage 转换为 NSData 并与核心数据一起保存

iphone - Ios加密。?

iphone - 计算每 N 个字符的换行符?