[英]how to change the UIBarButtonItem size when rotate from the portrait to landscape?
我將一個UISegmentedControl添加到導航欄。 當視圖以縱向加載時,其框架似乎正確。 但是當旋轉到橫向時,UIBarButtonItem會變大。 如果再次旋轉至縱向,它將仍然保持較大的水平。
一些代碼段在這里:
#define SEGMENT_WIDTH 100.0
#define SEGMENT_HEIGHT 32.0
CGRect segmentedControlRect = CGRectMake(0, 0, SEGMENT_WIDTH, SEGMENT_HEIGHT);
segmentedControl = [[UISegmentedControl alloc] initWithFrame:segmentedControlRect];
segmentedControl.momentary = NO;
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBordered;
[segmentedControl addTarget:self action:@selector(tabButtonPressed:) forControlEvents:UIControlEventValueChanged];
UIBarButtonItem *segmentBarBtn = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl];
self.navigationItem.rightBarButtonItem = segmentBarBtn;
一些截圖如下:
從縱向模式加載。
旋轉到風景模式。
旋轉回到縱向模式。
任何建議將不勝感激。
不要在導航欄中使用帶邊框的樣式! 使用UISegmentedControlStyleBar
。 那就是它的目的。
另外,請勿設置分段控件的大小(框架)。 只需使用alloc-init
創建它,然后允許它使用自己的固有大小調整規則( sizeToFit
)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.