【发布时间】:2015-10-07 07:43:50
【问题描述】:
我的应用程序有一个带有图像按钮的工具栏(UIButton 的子类);当用户打开“粗体文本”可访问性选项时,不仅文本变为粗体,图像也随之变为粗体。
这是正常模式下的工具栏:
启用“粗体”时:
这似乎是由我的 UIButton 子类引起的,它包含在下面。我正在使用此类在单击、禁用按钮等时应用图像色调颜色,并防止必须包含每个按钮的多个状态。为此,我使用了UIImageRenderingModeAlwaysTemplate,reportedly 表现出这种观察到的行为。
我尝试取消选中界面构建器中的“辅助功能”选项,但根本没有效果。有没有办法解决这个问题?
#import "AppButton.h"
@implementation AppButton
- (id)initWithCoder:(NSCoder *)aDecoder
{
if (self = [super initWithCoder:aDecoder]) {
[self initialize];
}
return self;
}
- (void)initialize
{
self.adjustsImageWhenHighlighted = NO;
[self setImage:[[self imageForState:UIControlStateNormal] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
}
- (void)updateButtonView
{
if (!self.enabled) {
self.imageView.tintColor = [UIColor colorWithRGBValue:RGBValueC9];
} else if (self.highlighted) {
self.imageView.tintColor = self.highlightTintColor;
} else {
self.imageView.tintColor = self.tintColor;
}
}
- (void)setHighlighted:(BOOL)highlighted
{
[super setHighlighted:highlighted];
[self updateButtonView];
}
- (void)setEnabled:(BOOL)enabled
{
[super setEnabled:enabled];
[self updateButtonView];
}
- (void)setTintColor:(UIColor *)tintColor
{
[super setTintColor:tintColor];
[self updateButtonView];
}
@end
【问题讨论】:
-
你能否参考@Kirby Todd 的答案来应用 Tint Color 而不是你使用 RenderingModeAlwaysTemplate 使用的默认颜色。stackoverflow.com/questions/19829356/color-tint-uibutton-image
-
多么奇怪的功能!刚刚在我的应用程序中遇到了这个问题。这在任何地方都有记录吗!?
标签: ios objective-c interface uibutton