自定义搜索框-输入框光标不贴边

//

//  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, width: 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, width: 0, height: 0))

}

// 左视图 位置

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

}

// 右视图 位置

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: self.frame.size.height)

return newBounds

}

required init?(coder aDecoder: NSCoder) {

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

}

}

时间: 2024-07-31 05:35:14

自定义搜索框-输入框光标不贴边的相关文章

Qt之自定义搜索框——QLineEdit里增加一个Layout,还不影响正常输入文字(好像是一种比较通吃的方法)

简述 关于搜索框,大家都经常接触.例如:浏览器搜索.Windows资源管理器搜索等. 当然,这些对于Qt实现来说毫无压力,只要思路清晰,分分钟搞定. 方案一:调用QLineEdit现有接口 void addAction(QAction * action, ActionPosition position) 在QLineEdit的前/后添加部件,ActionPosition表示部件所在方位. QAction * addAction(const QIcon & icon, ActionPosition

Android自定义View——自定义搜索框(SearchView)

概述 在Android开发中,当系统数据项比较多时,常常会在app添加搜索功能,方便用户能快速获得需要的数据.搜索栏对于我们并不陌生,在许多app都能见到它,比如豌豆荚 在某些情况下,我们希望我们的自动补全信息可以不只是纯文本,还可以像豌豆荚这样,能显示相应的图片和其他数据信息,因此Android给我们提供的AutoCompleteTextView往往就不够用,在大多情况下我们都需要自己去实现搜索框. 分析 根据上面这张图,简单分析一下自定义搜索框的结构与功能,有 1. 搜索界面大致由三部门组成

“商城项目”自定义搜索框

1.要实现搜索的效果图如下:<功能:当输入关键字点击搜索按钮的时候在list上显示出来,点击商品进入商品详情页即可> 2>自定义搜索框,在导航栏视图上添加搜索视图,代码如下: 3>搜索结果的tableView,定义一个数组将解析数据的内容存取到数组中,将数组的个数加一,最后多得一行作为清除历史记录的一行 4>重要的一点就是:点击清除历史记录的时候,将保存到NSuserdefault的内容remove掉 5>最后将数据解析的内容传过去就行了,自定义搜索框就完成了. 注意点

iOS - 完全自定义搜索框

此项目已上传GitHub,支持pods安装,Awsearch git地址: https://github.com/adampei/AwSearch git上有详细说明 效果图大概长这样 这个库都能做什么? 自定义搜索的icon, icon大小, icon位置, 搜索框背景色, 位置, 圆角等, 输入框字体大小, 颜色, placeholder字体大小, 颜色等, 右侧按钮字体大小, 背景色, 图片, 背景图等详细说明在GitHub,喜欢的话可以给个star谢谢 原文地址:https://www.

IOS自定义搜索框

如果只是在某个地方添加一个自定义的搜索框,只需要添加以下代码: //创建搜索框对象 UITextField *searchBar=[[UITextField alloc] init]; searchBar.width=300; searchBar.height=30; searchBar.font=[UIFont systemFontofSize:15]; [email protected]"请输入搜索框"; searchBar.backgroud=[UIImage imageName

WPF 自定义搜索框

  控件中的搜索图标下载地址:http://www.easyicon.net/1183666-Search_icon.html 搜索框设计过程比较简单: 1.先定义一个Rectangle作为背景 2.然后中间放TextBox输入,可以重写其中的模板.提示语Label放在模板中,可以在模板的触发器中控制隐藏显示~ 3.搜索按钮-大家随便在网上下个就行了. UserControl界面: <UserControl x:Class="WpfApplication18.SearchControl&q

【UI集合】- 自定义搜索框

疑问:看到好多APP上,导航栏上都有个搜索框,这个UI部分是肿么实现的呢...???

Android自定义搜索框

搜索框里的虚拟键盘 xml如下 <EditText android:id="@+id/et_shopshow_search" android:layout_width="144dp" android:layout_height="40dp" android:singleLine="true" android:paddingLeft="8dp" android:paddingRight="8d

猫猫学iOS 之微博项目实战(5)微博自定义搜索框searchBar

猫猫分享,必须精品 原创文章,欢迎转载.转载请注明:翟乃玉的博客 地址:http://blog.csdn.net/u013357243 一:效果 用UITextField简单定义一个搜索框 二:调用: 调用的代码,很简单,直接init就可以,以后加功能自己添加就行了. - (void)viewDidLoad { [super viewDidLoad]; // 创建搜索框 NYSearchBar *searchBar = [[NYSearchBar alloc] initWithFrame:CGR