我通过代码添加了日期标签和分享按钮。现在我想在右上角添加一个静态按钮来打开一个滑出菜单(我正在使用MMDrawerController)。如果我正在添加通道代码,它就会随着旋转木马移动。
如果我在故事板上的名称标签(我的应用程序)上添加一个按钮,则不会点击该按钮并且正在注册轮播手势而不是按钮点击。
如何继续为右侧的滑出菜单添加按钮?
-(UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view{
UIView *magView = nil;
CGFloat height = self.myCarousel.bounds.size.height;
CGFloat width = self.myCarousel.bounds.size.width;
//Magazine View
magView = [[UIView alloc] initWithFrame:CGRectMake(0, 40, width/1.35, height/1.75)];
magView.backgroundColor = [UIColor clearColor];
UIImageView *magImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"4 1:2.jpg"]];
magImage.frame = CGRectMake(0, 0, width/1.35, height/1.75);
[magView addSubview:magImage];
//Date Label
UILabel *dateLabel = nil;
dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, height/1.7, width/4, height/25)];
dateLabel.backgroundColor = [UIColor clearColor];
dateLabel.text = @"12-03-2017";
dateLabel.font = [UIFont fontWithName:@"Roboto-Black" size:5];
dateLabel.textColor = [UIColor whiteColor];
//Share Button
UIButton *shareButton = nil;
shareButton = [[UIButton alloc] initWithFrame:CGRectMake(width/1.49, height/1.7, height/25, height/25)];
shareButton.backgroundColor = [UIColor clearColor];
[shareButton setBackgroundImage:[UIImage imageNamed:@"share_icon_1x"] forState:UIControlStateNormal];
[magView addSubview:dateLabel];
[magView addSubview:shareButton];
return magView;
}
模拟器
故事板
如何继续添加按钮?
答案 0 :(得分:1)
添加按钮到故事板并以编程方式添加轮播后。添加代码以将按钮置于视图顶部。
[self.view bringSubviewToFront:button];
如果您以编程方式添加它,那么就在[self.view addSubview:carousel];
之后
调用[self.view bringSubviewToFront:button]
(确保在调用之前在视图上添加按钮)
答案 1 :(得分:1)
我解决了这个问题。我没有看到ViewController的视图,而是将另一个视图拖放到ViewController上并在其上显示轮播。现在我可以轻松设置按钮。谢谢你的帮助。干杯
答案 2 :(得分:0)
它会帮助您
[xyzButton.superview setUserInteractionEnabled:YES];
:)