2012-12-17 134 views
0

嗨有一个应用程序在哪里必须显示UISegmentedControls,但UISegment上的文本是从段向左。如何在UISegmented控制中心添加文本?如何在中心对齐UISegment文本

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

回答

0

试试这个:

optionControl.contentHorizontalAlignment=UIControlContentHorizontalAlignmentCenter;