问题TextField更改为搜索文本

时间:2011-06-25 09:39:56

标签: 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];
}

1 个答案:

答案 0 :(得分:1)

必须是borderStyle踢,即

text.borderStyle = UITextBorderStyleRoundedRect;

您可以使用UITextBorderStyleNone使用cornerRadius自定义边框样式。