0

I use this code to create a UISegment:

//segment controll

            NSString *key2 = [allKeys2 objectAtIndex:i];

            NSString *obj2 = [DictionaryHomework objectForKey:key2];

            int val;
            val = [obj2 intValue];

            //segment controll

            NSArray *itemArray2 = [NSArray arrayWithObjects: @"very easy", @"easy", @"ok", @"hard", @"challenging", nil];
            UISegmentedControl *segmentedControl2 = [[UISegmentedControl alloc] initWithItems:itemArray2];
            segmentedControl2.frame = CGRectMake(480, -60, 130, 350);
            segmentedControl2.segmentedControlStyle = UISegmentedControlStyleBar;
            segmentedControl2.selectedSegmentIndex = val - 1;
            [segmentedControl2 addTarget:self action:@selector(segmentedControlHomework:) forControlEvents:UIControlEventValueChanged];

            segmentedControl2.transform =
            CGAffineTransformRotate(segmentedControl2.transform, degreesToRadians(90));

            NSArray *arr = [segmentedControl2 subviews];
            for (int i = 0; i < [arr count]; i++) {
                UIView *v = (UIView*) [arr objectAtIndex:i];
                NSArray *subarr = [v subviews];
                for (int j = 0; j < [subarr count]; j++) {
                    if ([[subarr objectAtIndex:j] isKindOfClass:[UILabel class]]) {
                        UILabel *l = (UILabel*) [subarr objectAtIndex:j];
                        l.transform = CGAffineTransformMakeRotation(- M_PI / 2.0); //do the reverse of what Ben did
                    }
                }
            }

            [image1 addSubview:segmentedControl2];

            segmentedControl2.tag = i;

            [segmentArray addObject: segmentedControl2];

            //segment control

On ios5 the control loads the titles in horizontal, while in ios6 in vertical. Why is this? has there been a change in iOS6?

1 Answer 1

4

You are fiddling with the inner mechanics of the UISegmentedControl. While you are not technically using private APIs, you are still accessing parts of UIKit that are not publicly documented.

One reason the behavior might have changed in iOS 6 could be that the segmented control now builds its subviews lazily in layoutSubviews ore some other place. It might even not use subviews at all. But I'm just making guesses here. However, it's Apple's choice to change undocumented internals of the framework.

Your code should never have been used in a shipping app. If you want to do something like this (vertical segments?) that the build-in segmented control can't do, build it on your own.

1
  • 2
    Do what? Build a segmented control with vertical cells? You might use a table view. Sep 24, 2012 at 14:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.