zoukankan      html  css  js  c++  java
  • UITextField的文本框部分文本以*的方式来显示

     1 #import "AppDelegate.h"
     2 
     3 @interface AppDelegate ()<UITextFieldDelegate>// 添加代理协议
     4 
     5 @end
     6 
     7 @implementation AppDelegate
     8 
     9 
    10 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    11     self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    12     // Override point for customization after application launch.
    13     self.window.backgroundColor = [UIColor whiteColor];
    14     
    15 
    16     UITextField *tf = [[UITextField alloc] initWithFrame:CGRectMake(60, 100, 180, 30)];
    17     //确认代理
    18     tf.delegate = self;
    19     tf.keyboardType = UIKeyboardAppearanceDefault;
    20 
    21     tf.backgroundColor = [UIColor greenColor];
    22     [self.window addSubview:tf];
    23     
    24     [self.window makeKeyAndVisible];
    25     return YES;
    26 }
    27 
    28 - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
    29 {
    30     int length = [textField.text length];
    31     // 2代表*号的起始位置,9代表*号的结束位置
    32     if (length > 2 && length < 9) {
    33         NSMutableString *text = [textField.text mutableCopy];
    34         [text replaceCharactersInRange:NSMakeRange(length - 1 , 1) withString:@"*"];
    35         textField.text = text;
    36     }
    37     return YES;
    38 }
    39 
    40 @end

    实现的效果如下图:

                

  • 相关阅读:
    ajax请求传参数复杂对象list,后端springmvc接收参数
    SpringBoot热部署简介
    lucene 初探
    学生管理系统导包
    tomcat加入系统服务+开机自启
    sql like模糊查询的条件拼接
    SSHDemo
    Spring在web开发中的应用
    Spring的Bean内部方法调用无法使用AOP切面(CacheAble注解失效)
    dwz tree组件 取得所选择的值
  • 原文地址:https://www.cnblogs.com/lantu1989/p/4619232.html
Copyright © 2011-2022 走看看