【发布时间】:2017-08-04 11:16:31
【问题描述】:
我通过代码添加了日期标签和分享按钮。现在我想在右上角添加一个静态按钮来打开一个滑出菜单(我正在使用 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;
}
模拟器
故事板
如何继续添加按钮?
【问题讨论】:
-
将按钮添加到情节提要并在以编程方式添加轮播之后。添加代码以将按钮置于视图顶部。 [self.view bringSubviewToFront:button].
-
@pawan 我添加了将按钮置于视图顶部的代码,但没有用。即使我在标签上滑动,旋转木马也在移动。也许这就是按钮不起作用的原因
-
实际上,轮播是在视图顶部添加的。如果您以编程方式添加它,那么就在 [self.view addSubview:carousel]; 之后调用 [self.view bringSubviewToFront:button](确保在调用之前将按钮添加到视图中)
-
你不能在 icarousel 里面,所以你可以添加按钮,它是 UIVIew 的子视图
标签: ios objective-c icarousel