首页 > 解决方案 > UISegmentController 标题文本正在奇怪地切割

问题描述

在此处输入图像描述

见上图。

它是用 Objective-C 编程编写的。UISegmentController 正在剪切标题文本。

奇怪的是,它显示的“隐私政策”全文比“关于”和“条款”要长得多,后者正在切割。

有人可以帮忙吗?

代码如下:

    UISegmentedControl *unitsPicker                     = [[UISegmentedControl alloc] initWithItems:@[@"About", @"Terms", @"Privacy Policy"]];
    unitsPicker.frame                   = CGRectMake(0, CGRectGetMaxY(unitsLabel.frame) + kBottomPaddingConstant, CGRectGetWidth(_unitsContainer.frame), segmentHeightConstant);
    unitsPicker.autoresizingMask        = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
    unitsPicker.selectedSegmentIndex    = ![TemperatureUtility unitIsCelsius];
    [unitsPicker addTarget:self action:@selector(onUnitPickerChanged:) forControlEvents:UIControlEventValueChanged];
    unitsPicker.layer.cornerRadius   = 5.0f;
    unitsPicker.layer.borderColor    = [UIColorFromRGB(0xE9E9E9) CGColor];
    unitsPicker.layer.borderWidth    = 1.0f;
    unitsPicker.layer.masksToBounds  = YES;
    unitsPicker.clipsToBounds        = YES;
    [_unitsContainer addSubview:unitsPicker];

标签: iosobjective-cuisegmentedcontrolword-wrap

解决方案


尝试设置:

segmentedControl.apportionsSegmentWidthsByContent = YES;

从文档:

如果此属性的值为 true,则对于宽度值为 0 的段,控件会尝试根据其内容宽度调整段宽度。默认值为假。


推荐阅读