Coded UIStepper not displaying

66 Views Asked by At

After not finding an answer I have to again ask you all for help. I am creating a UIStepper programatically but it will not display. Labels, buttons, and switches are all displaying properly so I must be missing something related to the stepper.

Elsewhere in my code I declare and initialize UIView *v and NSMutableArray *steppers, and declare UIStepper *st. The code to create the stepper is:

st = [[UIStepper alloc] init];
st.frame = CGRectMake(xnear, ypos, 0, 0);
[st addTarget:self action:@selector(stepper1:) forControlEvents:UIControlEventValueChanged];
[st setMinimumValue:0];
[st setMaximumValue:99];
[st setWraps:NO];
[st setContinuous:NO];
[v addSubview:st];
[steppers addObject:st];

At runtime xnear = 100 and ypos = 250, so the stepper is within the display. A label immediately above, and a text field immediately below, are displaying. Other questions regarding the UIStepper state the width and height are ignored, so I used 0 for both. Is there anything obviously wrong with this code?

2

There are 2 best solutions below

0
On

You are setting height and width of UIStepper as 0

st.frame = CGRectMake(xnear, ypos, 0, 0);

give some height and width

st.frame = CGRectMake(xnear, ypos,200, 100);
0
On

The answer is, quite frankly, embarrassing. A custom background color was set for the UIView and no color was set for the control. I was able to get the stepper to show up with the following line of code:

st.backgroundColor = [UIColor whiteColor];

Similarly, the UISegmentedControl *sc showed up when I added:

sc.backgroundColor = [UIColor whiteColor];

Thanks for the help and sorry to waste your time!