ios - Add opaque subview to UITextField -



ios - Add opaque subview to UITextField -

i have subclass of uitextfield , i'm trying ot add together opaque subview it. however, when type in uitextfield, appears transparent , can see text behind view. how can create view opaque? here code inits subclass , adds view.

- (id)initwithframe:(cgrect)frame { self = [super initwithframe:frame]; if (self) { // initialization code _dropdownicon = [[uiimageview alloc] initwithimage:[uiimage imagenamed:@"ab- dropdown-on"]]; dropdownicon.backgroundcolor = [uicolor blackcolor]; _dropdownicon.frame = cgrectmake(self.frame.size.width-dropdown_icon_size,0,dropdown_icon_size,dropdown_icon_size); [self addsubview:_dropdownicon]; } homecoming self; }

your subclass needs override -textrectforbounds: method homecoming actual area want text draw in, e.g.

- (cgrect)textrectforbounds:(cgrect)bounds { cgrect textrect = [super textrectforbounds:bounds]; textrect.size.width -= 30; // or wide command is—play value homecoming textrect; }

what you’re seeing not icon beingness non-opaque—the text beingness drawn on it, because text field doesn’t “know” icon there.

you might rightview property , related -rightviewrectforbounds: method, though useful if want text field automatically show , hide accessory view.

ios objective-c uiview uitextfield opacity

Comments

Popular posts from this blog

javascript - mongodb won't find my schema method in nested container -

Hibernate criteria by a list of natural ids -

ios - Lagging ScrollView with UIWebview inside -