0
我UISegmentedControl工具欄上,當我添加自定義背景畫法工具欄分段控制移動近2px的下降,所以它不是垂直居中。下面是相應的圖像鏈接,請參閱screenshot和代碼的底部,我是如何加入分段控制程序工具欄:iPhone:UISegmentedController定製UIToolBar下移
segmentedControl = [[UISegmentedControl alloc] initWithItems:segmentedItems];
[segmentedControl addTarget:self action:@selector(tabChanged:) forControlEvents:UIControlEventValueChanged];
UIBarButtonItem *button1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
button1.style = UIBarButtonItemStylePlain;
UIBarButtonItem *button2 = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl];
button2.width = kSegmentedControlFrame.size.width;
button2.style = UIBarButtonItemStylePlain;
UIBarButtonItem *button3 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
button3.style = UIBarButtonItemStylePlain;
CGFloat y = self.contentView != nil ? self.contentView.frame.origin.y + self.contentView.frame.size.height : kToolbarFrame.origin.y;
UIToolbar *t = [[[UIToolbar alloc] initWithFrame:CGRectMake(kToolbarFrame.origin.x, y,
kToolbarFrame.size.width, kToolbarFrame.size.height)] autorelease];
[t setItems:[NSArray arrayWithObjects:button1, button2, button1 , nil]];
t.clipsToBounds = NO;
t.autoresizesSubviews = YES;
t.clearsContextBeforeDrawing = NO;
t.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleWidth
| UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin;
t.barStyle = UIBarStyleDefault;
t.tintColor = [UIColor clearColor];
t.contentMode = UIViewContentModeScaleToFill;
t.backgroundColor = [UIColor clearColor];
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControl.tintColor = [ColorUtil colorWithRed:129 withGreen:167 withBlue:186];
segmentedControl.frame = kSegmentedControlFrame; //CGRectMake(kSegmentedControlFrameX, kSegmentedControlY, kSegmentedControlWidth, kSegmentedControlHeight);
segmentedControl.selectedSegmentIndex = 0;
segmentedControl.contentVerticalAlignment = UIControlContentVerticalAlignmentTop;
segmentedControl.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
segmentedControl.clipsToBounds = NO;
segmentedControl.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin;
segmentedControl.center = CGPointMake(160, 22);
segmentedControl.momentary= NO;
[button1 release];
[button2 release];
[button3 release];
return t;
由於提前, 奈拉
沒有,工具欄不延長了屏幕的底部線的東西它定位。分段控制向下移動1px,其origin.y座標自動設置爲8,我不知道垂直居中如何。 –