Custom Search box-input box cursor not welt

Source: Internet
Author: User

//

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.