0

UINavigationBar全体に合うようにUITextFieldのサイズを設定するにはどうすればよいですか?これまでのところ私はこれを持っています:

    locationField = [[UITextField alloc] initWithFrame:CGRectMake(37,7,246,31)];
    locationField.delegate = self;
    locationField.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    locationField.textColor = [UIColor colorWithRed:102.0/255 green:102.0/255 blue:102.0/255 alpha:1.0];
    locationField.textAlignment = UITextAlignmentLeft;
    locationField.borderStyle = UITextBorderStyleRoundedRect;
    locationField.font = [UIFont fontWithName:@"Helvetica" size:15];
    locationField.autocorrectionType = UITextAutocorrectionTypeNo;
    locationField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;

locationField = [[UITextField alloc] initWithFrame:CGRectMake(37,7,246,31)];私は基本的にUINavigationBarに合わせたいと思っていますが、おそらくsizeToFitそれを実装する方法が100%確実ではありません。

ありがとう。

4

2 に答える 2

2

あなたは試すことができます

[self.navigationItem setTitleView:locationField];

以下のコードを参照してください。

    UITextField *locationField = [[UITextField alloc] initWithFrame:CGRectMake(37,7,246,31)];
    locationField.delegate = self;
    locationField.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    locationField.textColor = [UIColor colorWithRed:102.0/255 green:102.0/255 blue:102.0/255 alpha:1.0];
    locationField.textAlignment = UITextAlignmentLeft;
    locationField.borderStyle = UITextBorderStyleRoundedRect;
    locationField.font = [UIFont fontWithName:@"Helvetica" size:15];
    locationField.autocorrectionType = UITextAutocorrectionTypeNo;
    locationField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    [self.navigationItem setTitleView:locationField];
    [locationField release];
于 2012-06-16T21:31:53.903 に答える
0

気にしないでください。CGRectを次の場所から切り替えて修正してください。

UITextField *locationField = [[UITextField alloc] initWithFrame:CGRectMake(37,7,246,31)];

UITextField *locationField = [[UITextField alloc] initWithFrame:CGRectMake(37,7,300,31)];
于 2012-06-17T17:27:16.497 に答える