Iphone 将小图像放在UIImageView的顶部?
我在一个页面中有一个UIImageView,它从Interface builder获取它的图像,我试图在它的顶部放置小图标(这是一个小地图,我想在上面放置图标)。我知道这可能很简单,但我试图在文档中查找它,但这让我更加困惑。使用Interface Builder,您不能将UIImageView拖动到现有的UIImageView中吗?实际上,您最终将一个UIImageView嵌入到另一个UIImageView中 您还应该能够在代码中轻松设置“小地图”UIImageView的隐藏属性,具体取决于是否需要该UIImageView 希望这有帮助。祝你好运Iphone 将小图像放在UIImageView的顶部?,iphone,objective-c,uiimageview,Iphone,Objective C,Uiimageview,我在一个页面中有一个UIImageView,它从Interface builder获取它的图像,我试图在它的顶部放置小图标(这是一个小地图,我想在上面放置图标)。我知道这可能很简单,但我试图在文档中查找它,但这让我更加困惑。使用Interface Builder,您不能将UIImageView拖动到现有的UIImageView中吗?实际上,您最终将一个UIImageView嵌入到另一个UIImageView中 您还应该能够在代码中轻松设置“小地图”UIImageView的隐藏属性,具体取决于是否
- 让大家知道
-(id) initwithFrame:(CGRect) frame
{
if(self = [super initWithFrame:frame])
{
iContainer = [[UIView alloc] initWithFrame:frame];
[iContainer addSubViews:iLargerUIImageView];
[iContainer addSubViews:iSmallUIImageView];
[self.view addSubViews:iContainer];
}
return self;
}
-(void) layoutSubviews
{
CGRect myRect = self.frame;
iContainer.frame = myRect;
//Give the location to iLargerUIImageView as per your requirement.
iLargerUIImageView.frame = CGRectMake(...,...,...,...);
//Give the location to iSmallUIImageViewas per your requirement.
iSmallUIImageView.frame = CGRectMake(...,...,...,...);
}
-(void) dealloc
{
[iContainer release];
[iLargerUIImageView release];
[iSmallUIImageView release];
}
请尝试以下代码:
UIImageView*backgroundImageView=(UIImageView*)[带标记的自视图:kBckGndImag]
if(!backgroundImageView){
UIImage *imageName = [UIImage imageNamed:kpointsChartBig];
backgroundImageView = [[UIImageView alloc] initWithFrame:CGRectMake(15, 15, imageName.size.width, imageName.size.height)];
backgroundImageView.image=imageName;
[backgroundImageView setTag:kBckGndImag];
[pointImageView addSubview:backgroundImageView];
[backgroundImageView release];
}
UIImageView *foregroundImageView = (UIImageView *)[self viewWithTag:kForGndImage];
if(!foregroundImageView){
foregroundImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:kpointsColoredChartBig]];
foregroundImageView.contentMode = UIViewContentModeLeft;
foregroundImageView.clipsToBounds = YES;
[pointImageView addSubview:foregroundImageView];
[foregroundImageView release];
}
我刚刚发现,当您使用IB添加UIImageView时,它会将其视为一个简单的uiview。因此,只需创建新的UIImageView并在其中加载图像,然后将其作为子视图添加到self.view,它就会动态添加到视图中。谢谢,问题是我试图获取不存在的图像视图。。。当我将新的uiimageview添加到self.view时,它开始工作了,谢谢:)我刚刚发现uiimageview应该单独分配,并作为子视图添加到视图中。我想问一下,你错过了为Foreground ImageYeah你有鹰眼。foregroundImageView.frame=CGRectMake(15,15,backgroundImageView.frame.size.width*mPercent/100,foregroundImageView.bounds.size.height);