0

I have a UIButton class with a NSMutableAttributedString as the title (for the formatting). I would like to now change the titleColor of the button text from my vc class because it has been'selected'.

I can do it fine as a normal button title. But as a NSMutableAttributedString - no dice.

Some questions/advice: As the custom class view is already a button - should my color update happen in that class - and not from the vc? Just tell it to update and bake the color in the custom class?

Do I expose the NSMutableAttributedString property for the button's title so that I can access from my VC and change the color? This way I could also pass in new text as well as a new color.

In my CircleButton m file

NSMutableParagraphStyle *style = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
        [style setAlignment:NSTextAlignmentCenter];
        [style setLineBreakMode:NSLineBreakByWordWrapping];

        UIFont *font1 = [UIFont fontWithName:@"Futura" size:20.0f];
        NSDictionary *dict1 = @{NSUnderlineStyleAttributeName:@(NSUnderlineStyleNone),
                                NSFontAttributeName:font1,
                                NSForegroundColorAttributeName:textClr,
                                NSParagraphStyleAttributeName:style};

        attributedTText = [[NSAttributedString alloc] initWithString:btnTxt    attributes:dict1];
        [[button titleLabel] setNumberOfLines:0];
        [[button titleLabel] setLineBreakMode:NSLineBreakByWordWrapping];
        [button setAttributedTitle:attributedTText forState:UIControlStateNormal];
        [button setTitleColor:textClr forState:UIControlStateNormal];
malaki1974
  • 1,605
  • 3
  • 16
  • 32
  • The `forState:` argument when setting button properties isn't ignored you know. – nhgrif Jun 02 '14 at 21:22
  • I don't actually change the button to selected - so if you are referring to [button setTitleColor:textClr forState:UIControlStateSelected]; it will not help me. I just want to change the text on demand. – malaki1974 Jun 02 '14 at 21:37

0 Answers0