如何在中心对齐UISegment文本

时间:2012-12-17 12:45:26

标签: objective-c ios ios5 uisegmentedcontrol

你有一个应用程序,其中必须显示UISegmentedControls,但UISegment上的文本是从左边的段出来。如何在UISegmented控制中心algin文本?

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];

1 个答案:

答案 0 :(得分:0)

试试这个:

optionControl.contentHorizontalAlignment=UIControlContentHorizontalAlignmentCenter;