Note that there are some explanatory texts on larger screens.

plurals
  1. POAddtarget for UIControlStateNormal doesn't works
    primarykey
    data
    text
    <p>I've created a custom UIButton called SectionButton.</p> <p>The button have 2 images, one for the Normal State and other for Selected and Highlighted States.</p> <p>The button also have a text and when the button is pushed down, the TitleEdgesInset must be adjusted.</p> <p>In the init method I add the methods:</p> <pre><code>[self addTarget:self action: @selector(buttonHighlighted:) forControlEvents: UIControlStateHighlighted]; [self addTarget:self action:@selector(buttonNormal:) forControlEvents:UIControlStateNormal]; </code></pre> <p>But the method 'buttonNormal:' is never called, so I can't adjust the titleEdgeInsets property.</p> <pre><code>#import "SectionButton.h" @implementation SectionButton - (id)initWithFrame: (CGRect)frame andTitle: (NSString*)title andbaseImageName:(NSString*)imageBaseName { if (self = [super initWithFrame: frame]) { // Create images for button UIImage* normalImage = [UIImage imageNamed: imageBaseName ]; UIImage* downImage = [UIImage imageNamed:[NSString stringWithFormat:@"%@_selected",imageBaseName]]; // Set up button [self setTitle: [title uppercaseString] forState: UIControlStateNormal]; // Will be used for all states [self setTitleColor: [UIColor whiteColor] forState: UIControlStateNormal]; [self.titleLabel setFont:[UIFont fontWithName:@"Helvetica" size:12.0]]; [self setBackgroundImage: normalImage forState: UIControlStateNormal]; [self setBackgroundImage: downImage forState: UIControlStateHighlighted]; [self setContentEdgeInsets:UIEdgeInsetsMake(54, 0, 0, 0)]; [self addTarget: self action: @selector(buttonHighlighted:) forControlEvents: UIControlStateHighlighted]; [self addTarget:self action:@selector(buttonNormal:) forControlEvents:UIControlStateNormal]; } return self; } - (void)buttonHighlighted: (id)sender { [self setTitleEdgeInsets:UIEdgeInsetsMake(0,0,-16,0)]; NSLog(@"button selected"); } - (void) buttonNormal: (id)sender { [self setTitleEdgeInsets:UIEdgeInsetsMake(0,0,0,0)]; NSLog(@"Button normal"); } } @end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload