【问题标题】:How to Align the UISegment Text at the Centre如何在中心对齐 UISegment 文本
【发布时间】:2012-12-04 13:33:36
【问题描述】:

您好,有一个应用程序必须显示 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];

【问题讨论】:

    标签: objective-c ios ios5 uisegmentedcontrol


    【解决方案1】:

    试试这个:

    optionControl.contentHorizontalAlignment=UIControlContentHorizontalAlignmentCenter;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-30
      • 2013-07-13
      • 1970-01-01
      • 2015-09-04
      • 2020-01-10
      • 2011-03-01
      相关资源
      最近更新 更多