ios - 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];
解决方案
尝试设置:
segmentedControl.apportionsSegmentWidthsByContent = YES;
从文档:
如果此属性的值为 true,则对于宽度值为 0 的段,控件会尝试根据其内容宽度调整段宽度。默认值为假。
推荐阅读
- ios - How to unwrap an Optional Binding and pass value to another view?
- javascript - 当我向特定 URL 提交 ajax 请求时,它会被更改并给出 405(不允许的方法)?
- ios - 如何在 UICollectionView 中有上下文菜单和重新排序单元格?
- python - 如何使用 BeautifulSoup 获取 HTML 中按钮的内容
- c++ - 从 MS Visual C++ 编译器更改为英特尔 C++ 19.1 编译器时未解析的外部符号 __imp__fread
- opengl - 具有透明纹理渲染问题的 LibGDX (OpenGL) Mesh
- html - 使用 div 无法正确调整图像
- python - 如何在 Tensorflow 中为预取数据集绘制混淆矩阵
- php - 在 Javascript 中从 PHP 读取 Cookie 数据
- java - aws cognito 来宾用户使用 java 登录