zoukankan      html  css  js  c++  java
  • 自定义搜索框-输入框光标不贴边

    //

    //  RBCustomTextField.swift

    //

    //  Created by Touch on 16/4/27.

    //  Copyright © 2016年 renrenbx. All rights reserved.

    //

    import Foundation

    class RBCustomTextField: UITextField {

        

        override init(frame: CGRect) {

            super.init(frame: frame)

        }

        

        // 编辑状态内容显示位置

        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

        }

        

        // 解决输入问题位置偏移问题

        override func drawTextInRect(rect: CGRect) {

            super.drawTextInRect(CGRect(x: 8, y: self.frame.origin.y + 5.5, 0, height: 0))

        }

        

        // 占位符偏移

        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

        }

        

        // 解决占位符位置靠上问题

        override func drawPlaceholderInRect(rect: CGRect) {

            super.drawPlaceholderInRect(CGRect(x: 0, y: self.frame.size.height * 0.5 - 1, 0, height: 0))

        }

        

        // 左视图 位置

        override func leftViewRectForBounds(bounds: CGRect) -> CGRect {

            super.leftViewRectForBounds(bounds)

            

            let newBounds = CGRect(x: 0, y: 0, self.frame.size.height, height: self.frame.size.height)

            return newBounds

        }

        

        // 右视图 位置

        override func rightViewRectForBounds(bounds: CGRect) -> CGRect {

            super.rightViewRectForBounds(bounds)

            

            let newBounds = CGRect(x: self.frame.size.width - self.frame.size.height, y: 0, self.frame.size.height, height: self.frame.size.height)

            return newBounds

        }

        

        required init?(coder aDecoder: NSCoder) {

            fatalError("init(coder:) has not been implemented")

        }

    }

  • 相关阅读:
    ActiveMQ 默认用户名和密码
    # ActiveMQ连接超时问题(java.net.SocketException: Connection reset)
    SpringBoot(十) Logback 配置详解
    postgresql10以上的自动分区分表功能
    基于Redis实现延时队列服务
    Redis(十三):Redis分布式锁的正确实现方式
    Redis(十七):批量操作Pipeline
    Redis(十八):Redis和队列
    PostgreSQL SELECT INTO和INSERT INTO SELECT 两种表复制语句
    PostgreSQL 从文件时间戳获悉一些信息(如数据库创建时间)
  • 原文地址:https://www.cnblogs.com/madarax/p/5474565.html
Copyright © 2011-2022 走看看