ios - What's the correct way to put a line under a UITextField -
i want have borderless uitextfield underneath have 1 or 2 pixel high guide line underlines field. clear, don't want text inside uitextfield underlined, field, whether it's empty or full of text.
an example seen in example of google material design:
so of course stick in uiimage shows solid color , fit space, doesn't seem quite elegant, there better way that's more "correct" , future-proof if i'm worrying how code work several generations of ios down line , on knows devices?
p.s. rather scratch using obj-c find library.
i did yesterday... subclass uitextfield , work.
note: cleaner though use textfielddidbeginediting: , textfielddidendediting: changing of line height , color, either through nsnotificationcenter or delegate methods.
- (void)setup { self.hairlinelayer = [calayer layer]; self.hairlinelayer.backgroundcolor = [uicolor materialtextdarkdividercolor].cgcolor; [self.layer addsublayer:self.hairlinelayer]; } - (void)layoutsubviews { [super layoutsubviews]; cgfloat hairlineheight = 0; if (self.isfirstresponder) { self.hairlinelayer.backgroundcolor = [uicolor redcolor].cgcolor; hairlineheight = 1.4; } else { self.hairlinelayer.backgroundcolor = [uicolor graycolor].cgcolor; hairlineheight = 1/[uiscreen mainscreen].scale; } self.hairlinelayer.frame = cgrectmake(0, cgrectgetheight(self.bounds) - hairlineheight, cgrectgetwidth(self.bounds), hairlineheight); }
Comments
Post a Comment