textField更改占位文字颜色

2015-08-18  本文已影响302人  xdkoo
     unsigned int count = 0;
    Ivar *ivars = class_copyIvarList([UITextField class], &count);
    for (int i = 0; i < count; i++) {
        Ivar ivar = *(ivars + i);
        Ivar ivar = ivars[i];
        NSLog(@"%s",ivar_getName(ivar));
        
[self setValue:[UIColor whiteColor] forKeyPath:@"placeholderLabel.textColor"];
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    dict[NSForegroundColorAttributeName] = [UIColor whiteColor];
    NSAttributedString *str = [[NSAttributedString alloc] initWithString:self.placeholder attributes:dict];
    self.attributedPlaceholder = str;

-(void)drawPlaceholderInRect:(CGRect)rect
{
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    dict[NSForegroundColorAttributeName] = [UIColor whiteColor];
    CGRect newRect = CGRectMake(0, rect.size.height * 0.3, rect.size.width, rect.size.height);
    [self.placeholder drawInRect:newRect withAttributes:dict];
}

上一篇 下一篇

猜你喜欢

热点阅读