0

組み込みの検索範囲を で使用していますUISearchDisplayControllerが、2 つのセグメントしかありません。

問題は、私たちのデザインではボタンを小さくして中央に配置する必要があることです (特に iPad では、ボタンが非常に広く伸びているため見栄えが悪くなります)。

を中心にしUISegmentedControlて小さくする方法はありますか?をループしてすでにUISegmentedControl引き出されていsubViewsます。で各セグメントの幅を設定できますsetWidth:forSegmentAtIndexが、コントロールは左側にドッキングされています。どうすれば中央に配置できますか?

PS - 私のアプリは MonoTouch (Xamarin.iOS) ですが、Obj-C の回答は大歓迎です。

4

1 に答える 1

1

これをIB経由で追加していますか、それともプログラムで追加していますか? IB では、「Autoresize Subviews」をオフにして、コードを介してコントロールのサイズを動的に変更する必要がありました。サイズを変更する必要のあるコントロールを、バインドできるビューに配置し、コントロールをそのビューの中央に配置しました。これがサンプルです。ランドスケープモードで並べて配置した2つのボタンがありましたが、アイデアが得られるはずです.

// get the current sizes of the things we are moving
CGRect saveRect = self.viewButtons.frame;  // the enclosing view
CGRect addLocRect = self.buttonAddLocation.frame;  // button 1
CGRect connectRect = self.buttonConnect.frame;     // button 2

// This will be set below in one of the if-else branches
CGFloat buttonWidth = 0;

// determine the offset from the left/right based on device and orientation
int offsetLeft = 0;
int offsetRight = 0;
if ([self isIphone]) {
    offsetLeft = (UIDeviceOrientationIsPortrait(toInterfaceOrientation)) ? OFFSET_LEFT_PORTRAIT_IPHONE : OFFSET_LEFT_LANDSCAPE_IPHONE;
    offsetRight = (UIDeviceOrientationIsPortrait(toInterfaceOrientation)) ? OFFSET_RIGHT_PORTRAIT_IPHONE : OFFSET_RIGHT_LANDSCAPE_IPHONE;

} else {
    offsetLeft = (UIDeviceOrientationIsPortrait(toInterfaceOrientation)) ? OFFSET_LEFT_PORTRAIT_IPAD : OFFSET_LEFT_LANDSCAPE_IPAD;
    offsetRight = offsetLeft;
}


// change the size & location of the buttons to maximize the area for the location list
// no matter what orientation, the button frame will fill the bottom of the screen
saveRect.size.width = _windowWidth -offsetLeft - offsetRight;

// for Landscape, move the buttons to side-by-side at the bottom of the window
if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) {

    // size & move the buttons to fit side-by-side
    buttonWidth = (saveRect.size.width)*.4;

    // addLocRect.origin.x += offset;
    addLocRect.origin.y = saveRect.size.height - addLocRect.size.height ;

    connectRect.origin.x = saveRect.size.width - buttonWidth - offsetRight;
    connectRect.origin.y = saveRect.size.height - connectRect.size.height;

} else { // Portrait

    // move the buttons down to the bottom of the frame, stacked
    // size the buttons to be fully across the screen
    buttonWidth = saveRect.size.width-2*offsetLeft;

    addLocRect.origin.y = 0 ; // at the top of the button view
    addLocRect.origin.x = offsetLeft;
    connectRect.origin.y = saveRect.size.height - connectRect.size.height;
    connectRect.origin.x = offsetLeft;

}

connectRect.size.width = buttonWidth;
addLocRect.size.width = buttonWidth;
self.buttonAddLocation.frame = addLocRect;
self.buttonConnect.frame = connectRect;
于 2013-05-17T14:27:31.100 に答える