Frage

I have a UITextField with opacity 0.2 (the background is red), and I tried to add a white icon as textField.leftView like so:

    self.leftView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"lock.png"]];
    self.leftView.layer.opacity = 1.0;
    self.layer.opacity = 0.2;
    self.leftViewMode = UITextFieldViewModeAlways;

The problem is that the leftView seems to get the same opacity as the whole text field, and as they both are white, the result is that I see nothing. Do you see any other way/what I do wrong? Any help is appreciated.

War es hilfreich?

Lösung

Okay, found the solution. Seems I didn't think it fully through.

The problem was the opacity being "inherited" by all colors of the view, while I only wanted the background to be opaque. So, I just made the background opaque :) Like so:

    self.backgroundColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:0.2];
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top