//
Rbcustomtextfield.swift
//
Created by Touch on 16/4/27.
COPYRIGHT©2016 year RENRENBX. All rights reserved.
//
Import Foundation
Class Rbcustomtextfield:uitextfield {
Override Init (Frame:cgrect) {
Super.init (Frame:frame)
}
Edit State Content Display location
Override func Editingrectforbounds (bounds:cgrect), CGRect {
Super.editingrectforbounds (Bounds)
var newbounds = bounds
If Self.leftview?. Frame.size.width > 0{
newbounds.origin.x = bounds.origin.x + (Self.leftview?. Frame.size.width)!
}else{
newbounds.origin.x = bounds.origin.x + 8
}
NEWBOUNDS.ORIGIN.Y = bounds.origin.y + 1
Return Newbounds
}
Solve the problem of input problem location offset
Override func Drawtextinrect (rect:cgrect) {
Super.drawtextinrect (CGRect (x:8, Y:SELF.FRAME.ORIGIN.Y + 5.5, width:0, height:0))
}
Placeholder Offset
Override func Placeholderrectforbounds (bounds:cgrect), CGRect {
Super.placeholderrectforbounds (Bounds)
Echo ("Self.frame", Self.frame)
Echo ("Bounds", bounds)
var newbounds = bounds
newbounds.origin.x = bounds.origin.x + 8
NEWBOUNDS.ORIGIN.Y = 3
Echo ("Newbounds", Newbounds)
Return Newbounds
}
Resolving placeholder position top-up issues
Override func Drawplaceholderinrect (rect:cgrect) {
Super.drawplaceholderinrect (CGRect (x:0, Y:self.frame.size.height * 0.5-1, width:0, height:0))
}
Left view position
Override func Leftviewrectforbounds (bounds:cgrect), CGRect {
Super.leftviewrectforbounds (Bounds)
Let Newbounds = CGRect (x:0, y:0, Width:self.frame.size.height, Height:self.frame.size.height)
Return Newbounds
}
Right view position
Override func Rightviewrectforbounds (bounds:cgrect), CGRect {
Super.rightviewrectforbounds (Bounds)
Let Newbounds = CGRect (X:self.frame.size.width-self.frame.size.height, y:0, Width:self.frame.size.height, Height:sel F.frame.size.height)
Return Newbounds
}
Required init? (Coder Adecoder:nscoder) {
FatalError ("Init (coder:) have not been implemented")
}
}
Custom Search box-input box cursor not welt