我有一个菜单栏作为 uiimage。我想让这个菜单栏上的 5 个菜单可以点击并链接到另一个 View 。谁能告诉我该怎么做?我发现人们在 uiimage 上使用 uibutton,这对我来说很好吗?如何将菜单栏分成 5 block 。
感谢 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];
但是当我在模拟器上运行时,该按钮在屏幕上不可见。我做错什么了?
最佳答案
使用手势识别器是个坏主意,因为:
您应该做的是在 Photoshop 等图形工具中将单个图像分成五个,并将这些切片中的每个切片设为
image
。的 UIButton
.您需要为这些图像设计突出显示的状态(当其中一个被按住时显示),但无论如何您都应该这样做。如果必须在代码中对图像进行切片,可以使用
UIGraphicsBeginImageContextWithOptions(size, NO, 0.0)
来实现。并使用 drawAtPoint:
绘制大图使用适当的偏移量来获得您想要的切片,但是在 99.99999% 的情况下,在您的大型、功能强大、插墙式电源的 Mac 上切片图像一次比每次在小型应用程序上运行时更有意义,速度慢,电池供电的 iOS 设备。
关于ios - 如何制作可点击的uiimage?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16630736/