问题:如果用户使用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"。
答案 0 :(得分:1)
除第一行外,所有代码都很好。
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];
答案 1 :(得分:0)
除第一行外,所有代码都没有问题
buttonCurrent = [UIButton buttonWithType:UIButtonTypeCustom];
UIButtonTypeSystem
默认蓝色作为背景,大于iOS7。您应始终使用UIButtonTypeCustom
,以便它不会显示您的体验效果。