Ios segmented control. multi-line label with different colors for text and hue

I'm currently trying to implement a UISegmentedControl that uses a different text color on the border, but also spans multiple lines.

I managed to get both work separately, using this question for multi-line

Two lines of text in a UISegmentedControl

   for (id segment in [self.segmentedControl subviews]) {
    for (id label in [segment subviews]) {
        if ([label isKindOfClass:[UILabel class]]) {
            UILabel *titleLabel = (UILabel *) label;
            titleLabel.numberOfLines = 0;
            [titleLabel setTextColor:[UIColor redColor]];
        }
    }  
}

and using the Appearance proxy for the text color:

     [ [UISegmentedControl appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor redColor]} forState:UIControlStateNormal  ];

However, as soon as I combine both solutions, I lose multi-line abilities! I tried to put the code in different orders, so I scroll the labels after using the appearance proxy, but this does not work. I also tried using a custom NSParagraphStyle using the lineBreakingMode NSLineBreakByWorkWrapping method, but this does not work either.

- , ?

+4

Source: https://habr.com/ru/post/1528117/


All Articles