簡単なコードは次のとおりです。
カスタム MyButton.h
@interface PaiLifeReadingListButton : UIButton
@property (strong, nonatomic) UIImageView *logoImageView;
@end
カスタム MyButton.m
@implementation PaiLifeReadingListButton
@synthesize logoImageView = _logoImageView;
-(id)init
{
_logoImageView = [[UIImageView alloc] initWithFrame:CGRectMake(33.0, 20.0, 80.0, 80.0)];
[_logoImageView setImage:[UIImage imageNamed:@"pic"]];
[self addSubview: _logoImageView];
}
@end
カスタム MyView.h:
@property (strong, nonatomic) Mybutton *mybutton;
カスタム MyView.m:
-(id) init
{
myButton = [[MyButton alloc] init];
[self addSubview:myButton];
}
ViewController.m:
@synthesize myView;
- (void)viewDidLoad
{
myView = [[Myview alloc] init];
[myView.myButton addTarget:self action:@selector(pressed:) forControlEvents:UIControlEventTouchDown];
self.view = myView;
}
-(void)pressed : (MyButton *)button
{
UIImageView *newImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"other-pic"] highlightedImage:nil];
myView.myButton.logImageView = newImageView;
[self.view setNeedsDisplay]; //----this does not work
}
ボタンを押してもイメージビューが変わりません。どうすればこれを修正できますか? どうもありがとうございました!