【发布时间】:2017-06-24 06:34:10
【问题描述】:
我在情节提要中创建了一个图像。我以编程方式添加了一个按钮并添加到视图中。
UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
button.frame = CGRectMake(30,30,30,30);
button.layer.borderColor = [[UIColor blackColor] CGColor];
button.layer.borderWidth = 0.5f;
[imageView addSubview:button];
这两个是重叠的,后面的按钮是不可见的,但是可以执行它的动作。我尝试将此按钮放在图像上,
[imageView bringSubViewToFront:button];
但它不起作用。
【问题讨论】:
-
您似乎没有设置按钮框架。
-
我已经设置好了框架,只是没提。
-
如果您的按钮不是动态的,那么您可以直接从情节提要将其添加到图像视图上,而不是通过编程方式添加。否则以编程方式创建图像视图并添加按钮之后它将起作用。
-
你必须在你的视图中添加Subview你的按钮,而不是在 imageView 中。
-
您是否在按钮中设置了文本?并确保它没有被隐藏?并确保您在视图中添加了图像视图?
标签: ios objective-c xcode uiimageview subview