Wednesday, February 25, 2015

Create Attribute Text button


- (void)configureAttributedTextSystemButton {
    // Set the button's title for normal state.
    NSDictionary *normalTitleAttributes = @{
               NSForegroundColorAttributeName: [UIColor customBlueColor],
               NSStrikethroughStyleAttributeName: @(NSUnderlineStyleSingle)
                                        };
    
    NSAttributedString *normalAttributedTitle = [[NSAttributedString alloc]
               initWithString:NSLocalizedString(@"Button", nil)
               attributes:normalTitleAttributes];

    [self.attributedTextButton setAttributedTitle:normalAttributedTitle 
               forState:UIControlStateNormal];
    
    // Set the button's title for highlighted state.
    NSDictionary *highlightedTitleAttributes = @{                                                         
             NSForegroundColorAttributeName : [UIColor customGreenColor],                                                
             NSStrikethroughStyleAttributeName: @(NSUnderlineStyleThick)
                                             };
    
    NSAttributedString *highlightedAttributedTitle = [[NSAttributedString
            alloc] initWithString:NSLocalizedString(@"Button", nil)        
            attributes:highlightedTitleAttributes];

    [self.attributedTextButton setAttributedTitle:highlightedAttributedTitle
            forState:UIControlStateHighlighted];
    
    [self.attributedTextButton addTarget:self   
            action:@selector(buttonClicked:) 
            forControlEvents:UIControlEventTouchUpInside];

}




No comments:

Post a Comment