给UITextField设置头或尾空白

有时候,我们需要在UITextField的头尾加入一些空白,如下图所示:

其中,黄色和红色部分代表空白。

实现起来,比较简单,只需要设置UITextField的leftView、leftViewMode和rightView、rightViewMode即可,代码如下:

假设现有UItextField * txtField;

    UIView * rView =[[UIView alloc] initWithFrame:CGRectMake(txtField.frame.size.width - 10, 0, 10, txtField.frame.size.height)];
    rView.backgroundColor = [UIColor redColor];
    txtField.rightView = rView;
    txtField.rightViewMode = UITextFieldViewModeAlways;
    UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, txtField.frame.size.height)];
    view.backgroundColor = [UIColor yellowColor];
    txtField.leftViewMode = UITextFieldViewModeAlways;
    txtField.leftView = view;

给UITextField设置头或尾空白,布布扣,bubuko.com

时间: 2024-08-10 02:11:28

给UITextField设置头或尾空白的相关文章

使用 collectionView 实现表头,区头,区尾

UICollectionView 的使用是跟表的使用是一样,瀑布流的布局会比表的效果更好,这里说一下 collectionView 设置表头, 区头,区尾 设置表头可以约束 collectionView 居上的距离 其中区头,区尾 是继承 UICollectionReusableView 1 // 2 // HomePageViewController.m 3 // MainStoryboard 4 // 5 // Created by mac on 16/4/21. 6 // Copyrigh

【京东账户】——Mysql/PHP/Ajax爬坑之页头页尾加载

一.引言 实现京东的账户项目,有一个小功能,页头页尾加载.要用到的是Apach环境,Mysql.PHP以及Ajax. 二.实现 原理: 用php文件分别写一个的页头和一个页尾,放在前后两个div里. 通过jquery发送一个请求 请求这个php. 再把里面的一些小按钮,小图标放在这个div里即可. <div id="header"></div> -- <div id="footer"></div> 小知识1:jquer

bootstrap-带有头和尾的面板

1.运行效果如图所示 2.实现代码如下 <!DOCTYPE html> <html> <head>     <meta charset="utf-8">     <meta http-equiv="X-UA-Compatible" content="IE=edge">     <title>面板--带有头和尾的面板</title>     <!-- 最新版本

PHP设置头信息,取得返回头信息

php 设置头信息,取得返回头信息 张映 发表于 2011-05-27 分类目录: php 设置请求的头信息,我们可以用header函数,可以用fsockopen,可以用curl等,本文主要讲的是用curl来设置头信息,并取得返回后的头信息. 一,请求方设置自己的头信息,header.php 查看复制打印? <?php function FormatHeader($url, $myIp = null,$xml = null) { // 解悉url $temp = parse_url($url);

2分钟 sublime设置自动行尾添加分号并换行:

18:03 2016/4/162分钟 sublime设置自动行尾添加分号并换行:注意:宏文件路径要用反斜杠/,2个\\会提示无法打开宏文件.不需要绝对路径很简单利用宏定义:1.录制宏:由于是录制动作宏,对于文档内容没有具体要求,随便什么格式都可以.本文以图片中的 JS 代码为例进行说明.首先将光标置于代码中任意一行任意位置,点击菜单栏“工具->录制宏” 或用快捷键 “CTRL+ Q”开始录制宏.Sublilme Text 3 用宏自动在行尾添加分号4当看到 Sublime Text 3 左下角状

【代码笔记】UITextField设置placeholder颜色

一,效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController : UIViewController <UITextFieldDelegate> @end RootViewController.m #import "RootViewController.h" @interface RootViewController () @end @i

UITextField设置leftView的Insets

Insets就是css中的padding 我们给UITextField设置了leftView,目的是在文本输入框左侧显示一个图标.但是在ios7里,这个图标会紧紧地挨着TextField的左边框,很不美观,所以就希望设置一个Insets.但是直接设置ImageView的bounds不行,需要用下面这个方法: @interface YLSTextField : UITextField -(id)initWithFrame:(CGRect)frame Icon:(UIImageView*)icon;

关于页头页尾的异步加载

在网站中许多页面的页头页尾,都是一样的.采用异步加载,减少代码复用率: 采用PHP+html+jQuery 方法: 1.在名为header.php的页面中:写入页头部分的html <?php header('Content-Type:text/html;charset=UTF-8;'); ?> <div id="top"> <p>页头部分html代码</p> </div> 2.在页面中index.html中:指定要引入页头的位

PyCharm 设置头文件

PyCharm 设置头文件 进入File --->settings---->Editor---->File and Code Templates----->Python Script 添加以下内容:(自定义,看个人使用需求) 1 2 #!/usr/bin/env python # encoding: utf-8