UIAlertView标题标签奇怪的背景颜色问题

时间:2013-06-03 07:26:41

标签: iphone ios uiviewcontroller uialertview

首先,我在我的视图控制器中显示这样的UIAlertView(真的没什么特别的):

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Thank you"
                                                        message:@"Successfully saved bookmark"
                                                       delegate:nil
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles:nil];
[alert show];

但正如您在屏幕截图中看到的那样,标题标签将我视图的背景作为背景颜色:

screenshot of UIAlertView

我甚至没有想到这可能来自哪里,这是我在视图控制器出现时如何设置样式:

- (void)viewDidLoad
{
    [super viewDidLoad];        
    // Do any additional setup after loading the view.
    self.title = @"Details";

    [self.view styleBackgroundColor];

    [self.saveToBookmarks configureButtonStyle];
    [self.getDirections configureButtonStyle];

    self.name.text = [simoItem name];
    self.relativeLocation.text = [self relativeLocationStringForLocation:[simoItem location]];
    self.address.text = [simoItem address];
    self.type.text = [self buildTypesString];

    [self.name styleMainLabel];
    [self.address styleSubLabel];
    [self.type styleSubLabel];
    [self.relativeLocation styleSubLabel];
}

尝试清理项目,从SIM卡中卸载应用程序并摇晃我的计算机但到目前为止没有任何操作...

编辑:根据请求添加了styleMainLabel的代码

-(void) styleMainLabel {
    //colors
    UIColor *backgroundColor = [Utilities getBackgoundColorPreference];
    UIColor *textColor = [Utilities getTextColorPreference];
    [self setBackgroundColor:backgroundColor];
    [self setTextColor:textColor];

    //text size styling
    self.font = [UIFont fontWithName:@"Tiresias PCfont" size:35.0];
    self.adjustsFontSizeToFitWidth = YES;
}

2 个答案:

答案 0 :(得分:0)

styleMainLabel代码中可能存在问题。因此,首先检查您的代码,然后再次检查您的代码。

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Thank you"
                                                        message:@"Successfully saved bookmark"
                                                       delegate:nil
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles:nil];
[alert show];

UILabel *theTitle = [alert valueForKey:@"_titleLabel"];
   [theTitle setBackgroundColor:[UIColor clearColor]];

答案 1 :(得分:0)

好的我修复了问题,这是由辅助功能事件回调中设置的某些CALayer颜色属性引起的。以下是导致问题的代码

- (void)accessibilityElementDidBecomeFocused {
    [super accessibilityElementDidBecomeFocused];
    CALayer *layer = [self layer];
    layer.backgroundColor = [[Utilities getFocusedBackgroundColorPreference] CGColor];
}

-(void) accessibilityElementDidLoseFocus {
    [super accessibilityElementDidLoseFocus];
    CALayer *layer = [self layer];
    layer.backgroundColor = [[Utilities getBackgoundColorPreference] CGColor];
}

我还没有解决它,但关闭辅助功能使它消失了。谢谢你的帮助。