0

嗨,有一个应用程序必须显示 UISegmentedControls 但 UISegment 上的文本从向左的段中出来。如何在 UISegmented 控件的中心添加文本?

optionControl = [[UISegmentedControl alloc]initWithItems:optionNameArr];                                
[optionControl setFrame:CGRectMake(ReportingPanelScrollView.frame.size.width/2.8+80, y_Val +x_Dis, 100, 30)];
UIFont *font = [UIFont systemFontOfSize:12.0f];
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:font,UITextAttributeFont,[UIColor darkTextColor],UITextAttributeTextColor,nil];
[optionControl setTitleTextAttributes:attributes forState:UIControlStateNormal];
optionControl.segmentedControlStyle = UISegmentedControlStyleBordered;

optionControl.tag = sectionHeader*2000+itemHeader+200;
NSString *tagStr = [NSString stringWithFormat:@"%d",optionControl.tag];
[optionItemControlDict setObject:optionSelectedTextArr forKey:tagStr];
[optionControl addTarget:self action:@selector(OptionControlSelected:) forControlEvents:UIControlEventValueChanged];

[ReportingPanelScrollView addSubview:optionControl];
[optionControl release];
4

1 回答 1

0

尝试这个:

optionControl.contentHorizontalAlignment=UIControlContentHorizontalAlignmentCenter;
于 2012-12-17T13:01:06.653 回答