如何突出文本字段?

How to highlight the textfield?

如果文本字段中没有任何内容,如何突出显示文本字段并在几秒钟后消除发光?

if (_TextField.text.length == 0) {
    _TextField.layer.borderWidth = 0.5f;
    _TextField.layer.borderColor = [[UIColor redColor] CGColor];
    _TextField.layer.cornerRadius = 5;
    _TextField.clipsToBounds = YES;

}
else if (usersHighestLevel == 0 && [_TextField.text isEqualToString:@"2"]){
    usersHighestLevel = 1;
    intForString = intForString + 1;
    [self questions];}
else if (usersHighestLevel == 0 && ![_TextField.text isEqualToString:@"2"]) {
    usersHighestLevel = 1;
    _TextField.text = nil;
    [self questions];
}
else if (usersHighestLevel == 1 && [_TextField.text isEqualToString:@"green"]) {
    usersHighestLevel = 2;
    intForString = intForString + 1;
    [self questions];
}

1.Import quartzcore 框架

2.Add shadowopacity,shadowColor...像这样,

_textField.layer.shadowOpacity = 1.0;   
_textField.layer.shadowRadius = 0.0;
_textField.layer.shadowColor = [UIColor blackColor].CGColor;
_textField.layer.shadowOffset = CGSizeMake(0.0, -1.0);
#import <QuartzCore/QuartzCore.h>

textField.layer.masksToBounds = NO;
textField.layer.shadowColor = [[UIColor blueColor] CGColor];
textField.layer.shadowOffset = CGSizeZero;
textField.layer.shadowRadius = 10.0f;
textField.layer.shadowOpacity = 1.0;

如果你想在几秒后隐藏边框或阴影,那么使用这个代码..这个是在 2 秒后改变的,但你可以根据需要添加秒数。

[NSTimer scheduledTimerWithTimeInterval:2.0
                             target:self
                           selector:@selector(doSomethingWhenTimeIsUp:)
                           userInfo:nil
                            repeats:NO];
- (void) doSomethingWhenTimeIsUp:(NSTimer*)t {

    // YES! Do something here that you want to hide after few seconds!!
     [textField setBorderStyle:UITextBorderStyleNone];

}

希望本文对您有所帮助.....