0
툴바에 UISegmentedControl이 있습니다. 툴바에 대한 사용자 정의 배경 그리기 메소드를 추가 할 때 분할 된 컨트롤이 거의 2px 아래로 이동하므로 수직으로 가운데 정렬되지 않습니다. 여기에 이미지 링크를 해당되고, 내가 도구 모음에 분할 컨트롤을 추가 한 방법 screenshot 코드의 맨 아래에 도구 모음을 참조하십시오 사전에iPhone : UISegmentedController on custom 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;
감사합니다, 나이라
아니요, 도구 모음이 화면 아래쪽으로 연장되어 있지 않음을 의미하는
origin.y
값으로 배치 해보십시오. 분할 된 컨트롤은 1 픽셀 아래로 이동하고 origin.y 좌표는 자동으로 8로 설정되며 세로로 가운데에 배치하는 방법을 알지 못합니다. –