我一直在思考如何在按下按钮时更改UIView上的项目。我想要做的是在其上放置带有文本的UITextView,然后按一个按钮并在屏幕上显示UIImage。我不知道怎么做是如何把它们放在同一个视图上。任何帮助将不胜感激!
答案 0 :(得分:0)
要清除您需要执行的UIView
的内容:
for (UIView *view in [self.view subviews]) {
[view removeFromSuperview];
}
您需要做的只是将新的UIImage
添加到UIImageView
而不是:
[view addSubView:myImageView];
它应该是这样的:
UIImage *myImage = [UIImage imageNamed:@"image name"]; // This is the image (UIImage)
UIImageView *myImageView= [[UIImageView alloc] initWithImage:myImage]; // Insert the image to an UIImageView
[self.view addSubView:myImageView]; // Add the UIImageView to the view
运行所有这些代码将:
答案 1 :(得分:0)
1.在textview上放置一个IBoutlet uiimageview
2.at viewdidload设置其属性隐藏为是
3.按钮单击方法将其隐藏属性设置为NO
UIImage *myImage = [UIImage imageNamed:@"image name"];
IBOutlet UIImageView *myImageView= [[UIImageView alloc] initWithImage:myImage];
将此连接到uitextview上的imageview,您要在其中修复该图像 在按钮方法中添加此行
myImageView.hidden = NO;