ios - 问题 TextField 更改为搜索文本

标签 ios cocoa-touch ipad uitextfield

enter image description here

我正在为我的文本创建文本字段。

当我创建它时,它会显示一条附加到我的文本字段的线。

我附上了这张图片..

我的代码是

-(void)createTextField{

    if (([[UIDevice currentDevice]orientation]==UIDeviceOrientationLandscapeLeft)||([[UIDevice currentDevice]orientation]==UIDeviceOrientationLandscapeRight)) {
        [text setFrame:CGRectMake(640, 15, 300,40)];    
    }
    else {
        [text setFrame:CGRectMake(390,15,300,50)];
    }


    text.font = [UIFont systemFontOfSize:20];
    text.layer.cornerRadius = 20;
    text.delegate=self; 
    [text setTextColor:[UIColor blackColor]];
    text.alpha=1.0;
    text.autocorrectionType = UITextAutocorrectionTypeNo;
    text.returnKeyType=UIReturnKeySearch;
    UIImageView *searchLogo = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon-search-black.png"]];
    [text  setLeftView:searchLogo];
    [text setLeftViewMode:UITextFieldViewModeAlways];
    [searchLogo release];
    text.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    text.borderStyle=UITextBorderStyleRoundedRect;
    [text setBackgroundColor:[UIColor whiteColor]];

    [text setHidden:NO];
    [self addSubview:text];
    [text becomeFirstResponder];
}

最佳答案

它必须是 borderStyle 踢进来,即

text.borderStyle = UITextBorderStyleRoundedRect;

您可以使用 UITextBorderStyleNone,因为您已经使用 cornerRadius 自定义了边框样式。

关于ios - 问题 TextField 更改为搜索文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6477018/

相关文章:

ios - 如何防止物理体改变 Sprite Kit 中的 x 位置

objective-c - 通过 SSH 从 iOS 远程重新启动/关闭 mac?

cocoa-touch - 如何让AVPlayer播放多个项目?

ipad - TabBar 中的 UISplitViewController ( UITabBarController )?

iphone - removeFromSuperview 和释放内存管理

iphone - ios 确定应用程序如何启动

ios - 我们可以使用自定义 wifi 热点来欺骗 ipod 中的位置吗?

ios - 使用 iCloud 启用 Core Data NSArray-take 方法

objective-c - 为什么不使用界面生成器

ios - UIImageView+AF联网及保存图片