Two lines of text in a UISegmentedControl

后端 未结 3 1043
日久生厌
日久生厌 2020-12-15 00:34

Try as I might, I can\'t solve a UISegmentedControl bug for an iOS7 iPhone app.

When I create the segmented control, I use this code:

NSArray *segmen         


        
3条回答
  •  孤城傲影
    2020-12-15 01:24

    Aha! Something about how the OS is handling the size of the label when it rotates is different from how it handles the label when it's created. So I forced the size of the frame of the label, using

    for (id segment in [_wheelDiameterSegmentedControl subviews]) {
    
        for (id label in [segment subviews]) {
    
            if ([label isKindOfClass:[UILabel class]]) {
    
                UILabel *titleLabel = (UILabel *) label;
    
                //inserting line here, to make the frame behave nicely:
                //
                titleLabel.frame = CGRectMake(0, 0, 97, 50);
                //
                //continuing as before
    
                titleLabel.numberOfLines = 0;
    
            }
        }
    }
    

    and now it displays exactly as I want/expect. Huzzah!


    If you're just trying to get two (or more) lines of text in your UISegmentedControl. Using Herzian's amazing technology! Here's just another code example, that may help people...

    self.yourSlider .. set the height manually (can't easily do it in XIB)
    // now use amazing Herzian technology...
    for (id segment in [self.yourSlider subviews])
        for (id label in [segment subviews])
            {
            if ([label isKindOfClass:[UILabel class]])
                {
                UILabel *titleLabel = (UILabel *) label;
                titleLabel .. set the width to say 80, per your layout;
                (the width us typically too low)
                titleLabel.numberOfLines = 0;
                }
            }
    

    thank you so much, again.

提交回复
热议问题