【问题标题】:How to highlight the textfield? [closed]如何突出显示文本字段? [关闭]
【发布时间】:2016-01-17 10:57:07
【问题描述】:

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

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];
}

【问题讨论】:

  • 我添加到问题中
  • 在过渡到下一个问题时,有必要将其删除。

标签: ios ios7


【解决方案1】:
#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];

}

希望这个对你有所帮助.....

【讨论】:

  • 几秒后如何去除阴影?
  • @Alex 现在检查我的答案,我在里面做了一些补充......
  • 我认为这个对您有帮助,如果您需要更多帮助,请告诉我..
【解决方案2】:

1.导入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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-26
    • 2015-01-08
    • 2014-04-03
    • 1970-01-01
    • 2018-05-20
    • 2013-02-18
    相关资源
    最近更新 更多