Today, I want to achieve in UIImageView above to add a UIButton, click the button after the output passage
But I can not be added to after clicking button.
I do not know where wrong
I was a beginner, you may issue is food. Find Great God pointing ah!
I took shots with code stickers out ah.
# import "AppDelegate.h"
@ implementation AppDelegate
- (BOOL) application: (UIApplication *) application didFinishLaunchingWithOptions: (NSDictionary *) launchOptions
{
self.window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
/ / Override point for customization after application launch.
self.window.backgroundColor = [UIColor yellowColor];
UIImageView * imgView = [[UIImageView alloc] initWithFrame: CGRectMake (80, 140, 160, 80)];
/ / imgView.highlighted = NO;
imgView.backgroundColor = [UIColor greenColor];
imgView.image = [UIImage imageNamed: @ "BB"];
[self.window addSubview: imgView];
UIButton * btn = [UIButton buttonWithType: UIButtonTypeRoundedRect];
btn.frame = CGRectMake (80, 40, 80, 40);
/ / btn.selected = YES;
[btn setTitle: @ "I" forState: UIControlStateNormal];
[btn setTitleColor: [UIColor redColor] forState: UIControlStateNormal];
[btn addTarget: self action: @ selector (touchUpInside) forControlEvents: UIControlEventTouchUpInside];
[imgView addSubview: btn];
/ / btn.enabled = YES;
[self.window makeKeyAndVisible];
return YES;
}
- (void) touchUpInside
{
NSLog (@ "touchUpInside");
}
< >
------ Solutions ----------------------------------- --------------------- < >
Passing by, hoping to find a master. < >
------ Solutions ----------------------------------- --------------------- < >
Because UIImageView default is not acceptable Touch events
So just add a imgView.userInteractionEnabled = YES;
< >
没有评论:
发表评论