我正在用iOS进行开发。我尝试使用Segmented Control,但Segmented Control的文本太长,如下图所示:

有没有什么方法可以在Segmented Control中显示所有文本?
发布于 2016-01-12 20:47:03
第一种方法:将字体大小更改为可在段中容纳的较小大小
UIFont *font = [UIFont boldSystemFontOfSize:12.0f];
NSDictionary *attributes = [NSDictionary dictionaryWithObject:font
forKey:NSFontAttributeName];
[segmentedControl setTitleTextAttributes:attributes
forState:UIControlStateNormal];第二种方式:根据文本设置线段的宽度。(感谢the_UB的评论)
请参考How can I calculate correct widths for UISegmentedControl segments?
的第三种方法:尝试使用像片段一样的滚动控件
请参阅:https://www.cocoacontrols.com/controls/carbonkit和https://www.cocoacontrols.com/controls/pagingmenucontroller
发布于 2019-03-15 20:33:03
也许这会帮助其他人
您可以像这样设置Segment Control的每一项的宽度
segmentedControl.setWidth(100, forSegmentAt: 0)
segmentedControl.setWidth(50, forSegmentAt: 1)或者这样
segmentedControl.apportionsSegmentWidthsByContent = truehttps://stackoverflow.com/questions/34743861
复制相似问题