Two lines of text in a UISegmentedControl

后端 未结 3 1041
日久生厌
日久生厌 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:19

    working code in ios 7 :

    I have a segment controller with four segments and I need it in 2 lines for text. So I have added UILabel as a subview in segment of UISegmentedControl and it is working good. I have tried all other ways but in ios 7 and ios 8 it is working good right now.

    for(int k =0;k<4;k++)
        {
            NSString *text = @"title name";
            UILabel *label = [[UILabel alloc] init];
            label.frame = CGRectMake(10,2, (self.segmentcontroll.frame.size.width/4), 34);
            label.font = [UIFont fontWithName:@"HelveticaNeue" size:12.0];
            label.textColor = [UIColor whiteColor];
            label.text = text;
            label.numberOfLines = 0;
            label.textAlignment = NSTextAlignmentCenter;
            [label sizeToFit];
            [[[self.segmentcontroll subviews] objectAtIndex:k] addSubview:label];
    }
    

提交回复
热议问题