3

I want to program a custom keyboard for a textfield. The background of the keyboard should be transparent, but when I try to set the alpha of the keyboardView, the alpha of its subviews changes too. How can I change the keyboard's alpha only? I don't want to set it to [UIColor clearColor].

keyboardView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
keyboardView.alpha = 0.2;
keyboardView.backgroundColor = [[UIColor clearColor] colorWithAlphaComponent];
Josef Büttgen
  • 131
  • 2
  • 12
  • Well I don't think it is possible to change the view but not it's subViews. The only thing I could imagine is to set it transparent **before** adding the subViews. Try that. – LinusGeffarth Mar 20 '15 at 18:46
  • as you can see this http://stackoverflow.com/questions/18681901/setting-alpha-on-uiview-sets-the-alpha-on-its-subviews-which-should-not-happen you can use next way: [parentView setBackgroundColor:[[UIColor clearColor] colorWithAlphaComponent:0.5]]; – stosha Mar 20 '15 at 18:52
  • It doesn't work setting it transparent before adding the subviews. And if I use setBackgroundColor: nothing happens. – Josef Büttgen Mar 20 '15 at 19:13

1 Answers1

4

Changing a view's alpha alters the view and all it's subviews.

If you want the non-drawn parts of your view to show what's underneath, set the view's opaque flag to NO and then set the background color to clearColor.

Duncan C
  • 128,072
  • 22
  • 173
  • 272
  • When I try this, there stays a grey opaque layer in the background. Do you have any ideas how I could remove it? – Josef Büttgen Mar 21 '15 at 01:21
  • It's probably one of your subviews. Try Selecting view debugging from the Xcode debug menu, and choose the "Capture View Hierarchy" menu item. Then rotate the resulting snapshot and look at the stack of views. Also try "Show view frames". You may need to set some of your subviews to opaque = NO and backgroundColor = clearColor as well. – Duncan C Mar 21 '15 at 01:57
  • Thank You for the hint, but I only see the view, my textfield is a subview of. So the keyboardView of this textfield isn't shown. – Josef Büttgen Mar 21 '15 at 02:19