问题:如果用户在 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/