Is it possible to create multi line UISegmentedControl?

后端 未结 5 427
不知归路
不知归路 2020-12-11 05:21

I have a relative longer text items in my segmented control so I need to break text at certain points. Is it possible to use line breaks? I know at buttons

5条回答
  •  囚心锁ツ
    2020-12-11 06:12

    Add [yourSegmentedControl layoutIfNeeded]; method, before adding it as a subview. Then iterate all the SegmentedControl subviews and modify the numberOfLines property of the title label.

    Here is the code

    for (id segmentItem in [yourSegmentedControl subviews])
    {
      if ([segmentItem isKindOfClass:[UILabel class]])
       {
         UILabel *titleLabel = (UILabel *) segmentItem;
         titleLabel.frame = CGRectMake(0, 0, 100, 50); //modify the frame if the second line is not showing.
         titleLabel.numberOfLines = 0;
       }
    }
    

提交回复
热议问题