我有一个菜单栏作为 uiimage。我想让这个菜单栏上的 5 个菜单是可点击的并链接到另一个视图。谁能告诉我该怎么做?我发现人们在 uiimage 上使用 uibutton,这对我来说很好吗,我怎样才能将菜单栏分成 5 块。
感谢 rmaddy 和 Brent Royal-Gordon
我决定使用 uiimage 作为菜单栏背景并在其上添加 uibutton。我尝试这样的事情:
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:@"MOVIE" ofType:@"MP4"]];
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
moviePlayer.controlStyle = MPMovieControlStyleNone;
moviePlayer.repeatMode = MPMovieRepeatModeOne;
moviePlayer.shouldAutoplay = YES;
moviePlayer.scalingMode = MPMovieScalingModeFill;
[moviePlayer.view setFrame:CGRectMake(0,0,1330,320)];
[scrollView setBackgroundColor:[UIColor blackColor]];
[scrollView setContentSize:CGSizeMake(1330,320)];
[scrollView setScrollEnabled: YES];
[scrollView setShowsHorizontalScrollIndicator:NO];
[scrollView setShowsVerticalScrollIndicator:NO];
[scrollView addSubview:moviePlayer.view];
[self.view addSubview:scrollView];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:image.frame];
UIImage *menubar = [UIImage imageNamed:@"BG.jpg"];
imageView = [[UIImageView alloc] initWithImage:menubar];
imageView.contentMode = UIViewContentModeScaleToFill;
imageView.frame = CGRectMake(0, 258, imageView.frame.size.width, 25);
[self.view addSubview:imageView];
[imageView setUserInteractionEnabled:YES];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setFrame:CGRectMake(0,258,30,25)];
[btn addTarget:self action:@selector(buttonPress:) forControlEvents:UIControlEventTouchUpInside];
[btn setTitle:@"HOME" forState:UIControlStateNormal];
[imageView addSubview:btn];
但是当我在模拟器上运行时,该按钮在屏幕上不可见。我做错了什么?