UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(20, 50, 120, 40)];
    
    NSDictionary *normalTitleAttributes = @{
                                            NSForegroundColorAttributeName: [UIColor blueColor],
                                            NSStrikethroughStyleAttributeName: @(NSUnderlineStyleSingle)
                                            };
    NSAttributedString *normalAttributedTitle = [[NSAttributedString alloc] initWithString:NSLocalizedString(@"Button", nil) attributes:normalTitleAttributes];
    [btn setAttributedTitle:normalAttributedTitle forState:UIControlStateNormal];
    
    // Set the button's title for highlighted state.
    NSDictionary *highlightedTitleAttributes = @{
                                                 NSForegroundColorAttributeName : [UIColor blueColor],
                                                 NSStrikethroughStyleAttributeName: @(NSUnderlineStyleThick)
                                                 };
    NSAttributedString *highlightedAttributedTitle = [[NSAttributedString alloc] initWithString:NSLocalizedString(@"Button", nil) attributes:highlightedTitleAttributes];
    [btn setAttributedTitle:highlightedAttributedTitle forState:UIControlStateHighlighted];
    
    [btn addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:btn];

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-12
  • 2022-01-17
  • 2022-12-23
  • 2022-12-23
  • 2021-06-11
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-03-04
  • 2022-02-07
  • 2022-12-23
相关资源
相似解决方案