如何在 imageView 上放置一个圆形矩形按钮,
我的图像视图:self.view addSubview:myImage
更新
感谢大家!这些真的对我有帮助。
如何在 imageView 上放置一个圆形矩形按钮,
我的图像视图:self.view addSubview:myImage
更新
感谢大家!这些真的对我有帮助。
UIButton *myButton=[UIButton buttonWithType:UIButtonTypeRoundedRect];
myButton.frame=CGRectMake(10,20,30,40); // set the size of the button here
[myImage addSubview:myButton];
[self.view addSubView:myImage];
UIImageView *contentView = [[UIImageView alloc] initWithFrame:CGRectMake(10,10,200,200)];
[contentView setImage:[UIImage imageNamed:@"helloworld.png"]];
UIButton *b=[[UIButton alloc] init];
b.center=CGPointMake(160, 240);
[b setImage:[UIImage imageNamed:@"icon.png"] forState:UIControlStateNormal];
[b addTarget:self action:@selector(showMenu) forControlEvents:UIControlEventTouchUpInside];
[contentView addSubview:b];
// Provide support for auto-rotation and resizing
contentView.autoresizesSubviews = YES;
contentView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
contentView.userIntractionEnabled = YES;
[self.view addSubView:contentView];
您可以在添加 imageView 后添加UIButton
(使用 type buttonWithType:UIButtonTypeCustom
) 。UIView
UIImageView *imgview=[[UIImageView alloc]init];
imgview.backgroundColor=[UIColor blackColor];
imgview.contentMode=UIViewContentModeScaleToFill;
UIButton *theButton=[UIButton buttonWithType:UIButtonTypeCustom];
theButton.tag=i;
[theButton addTarget:self action:@selector(buttonClicked:)
forControlEvents:UIControlEventTouchDown];
imgview.frame = CGRectMake(x, y, 95, 115);
[self.view addSubview:imgview];
theButton.frame = CGRectMake(x, y, 95, 115);
[imgview addSubview:theButton];
添加 imageView 后,只需在 View 中添加 UIButton(类型为 RoundedRectType)。
您可以将其添加为
UIButton *button=[UIButton buttonWithType:UIButtonTypeRoundedRect];
myButton.frame=CGRectMake(....); // specify the frame of the button as per your requirement
[imageView addSubview:myButton];
imageView.userInteractionEnabled=YES;`
您需要将图像视图的用户交互设置TRUE
为默认交互为FALSE
.