textField.placeholder颜色的修改

2017-03-20  本文已影响26人  奋斗的小老鼠

textField.placeholder颜色的修改方式,为自己做一个记录,希望能帮到有需要的朋友。

UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(15, 128, Kwidth - 30, 21)];
    //    textField.text = @"输入你想要直播的标题";
    textField.delegate = self;
    textField.placeholder = @"输入你想要直播的内容";
    
    //更改placeholder 的颜色
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    dict[NSForegroundColorAttributeName] = [UIColor whiteColor];
    NSAttributedString *attribute = [[NSAttributedString alloc] initWithString:textField.placeholder attributes:dict];
    [textField setAttributedPlaceholder:attribute];
    
    textField.textAlignment = NSTextAlignmentCenter;
    textField.textColor = [UIColor whiteColor];
    [view addSubview:textField];
上一篇下一篇

猜你喜欢

热点阅读