iOS:如何将图像动态添加到父视图? [英] iOS: How to dynamically add image to a parent view?

查看:32
本文介绍了iOS:如何将图像动态添加到父视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在屏幕上有一个主图像,并在其顶部放置了一个覆盖"UIView,背景颜色设置为清除颜色.我想在叠加视图中动态放置其他图像,如下所示:

I've got a main image on the screen, and have an "overlay" UIView placed on top of it with the background color set to Clear Color. I want to dynamically place other images inside the overlay view as follows:

UIImage* m_icon = [[UIImage alloc]initWithContentsOfFile:@"icon.png"]; 
UIImageView *imageView = [[UIImageView alloc] initWithImage:m_icon];
[m_OverlayView addSubview:imageView];

但是图标图像没有显示.我错过了什么?

But the icon image isn't showing up. What am I missing?

推荐答案

你可以试试:

NSString *icon_path = [[NSBundle mainBundle] pathForResource:@"icon" ofType:@"png"];
UIImage* m_icon = [[UIImage alloc]initWithContentsOfFile:icon_path]; 
UIImageView *imageView = [[UIImageView alloc] initWithImage:m_icon];
[m_OverlayView addSubview:imageView];

这篇关于iOS:如何将图像动态添加到父视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆