我在一个页面中有一个UIImageView,它从Interface构建器获取它的图像,我试图在它的顶部放置小图标(这是一个小地图,我想在其上放置图标)。我知道它可能很简单,但我试着在文档中查找它,但它让我更加困惑。
答案 0 :(得分:1)
使用Interface Builder,你不能只将UIImageView拖入现有的UIImageView吗?实际上,最终会将一个UIImageView嵌入另一个UIImageView中。
您还应该能够在代码中轻松设置“小地图”UIImageView的隐藏属性,具体取决于是否需要UIImageView。
希望这会有所帮助。祝你好运。
答案 1 :(得分:1)
你可以通过添加大小UIViewImage视图来编写自己的UIView。
我已经用Pseudocode说明了我的方法。
-(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];
}
答案 2 :(得分:0)
试试这段代码:
UIImageView * backgroundImageView =(UIImageView *)[self viewWithTag: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];
}