UITextfield

 1.光标颜色

textf.tintColor

光标位置

设置leftView来控制

2.文本框聚焦时调用的方法

- (BOOL)becomeFirstResponder

 3. 设置默认的占位文字颜色

 第一种

  [self setValue:[UIColor grayColor] forKeyPath:@"placeholderLabel.textColor"];

第二种

- (void)drawPlaceholderInRect:(CGRect)rect
{
    // 文字属性
    NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
    attrs[NSForegroundColorAttributeName] = [UIColor whiteColor];
    attrs[NSFontAttributeName] = self.font;
    
    // 画出占位文字
//    CGRect placeholderRect;
//    placeholderRect.size.width = rect.size.width;
//    placeholderRect.size.height = self.font.lineHeight;
//    placeholderRect.origin.x = 0;
//    placeholderRect.origin.y = (rect.size.height - self.font.lineHeight) * 0.5;
//    [self.placeholder drawInRect:placeholderRect withAttributes:attrs];
    
    CGPoint placeholderPoint = CGPointMake(0, (rect.size.height - self.font.lineHeight) * 0.5);
    [self.placeholder drawAtPoint:placeholderPoint withAttributes:attrs];
}

 4.当textfiled变为第一响应者时,改变占位字符的颜色

第一种方法

    重写- (BOOL)becomeFirstResponder

第二种方法

    taget-sel  监听状态:

UIControlEventEditingDidBegin

第三种方法

  设置代理为self,实现代理方法

5.字体的高度

self.font.lineHeight

原文地址:https://www.cnblogs.com/yintingting/p/4569200.html