2012-01-21 24 views
0

キーボードにUIToolbarを追加してUITextFieldを追加します。ここで私が使用しているコードされていますUIToolbarが奇妙な位置に表示されるのはなぜですか?

UIToolbar *toolbar = [[UIToolbar alloc] init]; 
    toolbar.tintColor = [UIColor blackColor]; 
    UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done" 
                    style:UIBarButtonItemStyleBordered 
                    target:self 
                    action:@selector(someFunction)]; 
    doneButton.tintColor = [UIColor blackColor]; 
    UISegmentedControl *directionControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Back", @"Next", nil]]; 
    directionControl.tintColor = [UIColor blackColor]; 
    directionControl.segmentedControlStyle = UISegmentedControlStyleBar; 
    [directionControl addTarget:self action:@selector(directionControlPressed) forControlEvents:UIControlEventValueChanged]; 
    UIBarButtonItem *segItem = [[UIBarButtonItem alloc] initWithCustomView:directionControl]; 
    UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; 
    [toolbar setItems:[NSArray arrayWithObjects:segItem, flexibleSpace, doneButton, nil]]; 

    // Assign the toolbar to the text fields 
    self.textField.inputAccessoryView = toolbar; 

はしかし、ここで私は、コードを実行すると、それは次のようになります。

enter image description here

toolbarは十分に高いとは思えません。私は、ツールバーの色合いが認識されていないことにも気付きました。

誰かが私を助けてくれますか?

答えて

1

ツールバーのフレームを少なくともそのサイズに設定する必要があると考えます。思い出したように、私は高さを得るために[toolbar sizeToFit]を使用し、幅を得るためにウィンドウ幅を使用しなければならなかった。

+0

これは完全に機能しました!それは、高さ、幅を解決し、色合いの色を固定しました。どうもありがとうございました! –

+0

ツールバーのサイズが「CGSizeZero」であるため、色合いが表示されませんでした。 – smparkes

関連する問題