将小图像放在 UIImageView 的顶部?

发布于 2024-10-21 21:57:53 字数 105 浏览 2 评论 0原文

我在页面中有一个 UIImageView,它从界面生成器获取其图像,我试图在其顶部放置小图标(这是一个小地图,我想在其上放置图标)。我知道这可能非常简单,但我尝试在文档中查找它,但这让我更加困惑。

I've got a UIImageView in a page that gets its image from the Interface builder and I'm trying to put small icons on the top of it (it's a small map and I want to put icons on it). I know it's probably very simple but I tried to look it up in the documentation but it pretty much got me more confused.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

往事随风而去 2024-10-28 21:57:53

使用 Interface Builder,您不能将 UIImageView 拖到现有的 UIImageView 中吗?实际上,您最终会将一个 UIImageView 嵌入到另一个 UIImageView 中。

您还应该能够在代码中轻松设置“小地图”UIImageView 的隐藏属性,具体取决于是否需要该 UIImageView。

希望这有帮助。祝你好运。

  • 让大家知道

Using Interface Builder, can't you just drag a UIImageView into an existing UIImageView? In effect, you end up with one UIImageView embedded within another.

You should also be able to easily set the hidden property of the "small map" UIImageView in code, depending on if that UIImageView is needed or not.

Hope this helps. Good Luck.

  • Let It Be Known
人心善变 2024-10-28 21:57:53

您可以通过添加大 UIViewImage 视图和小 UIViewImage 视图来构建自己的 UIView。

我在下面用伪代码说明了我的方法。

-(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];
}

you could compose your own UIView by adding both the large and small UIViewImage views.

I have illustrated my approach below with the 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];
}
夜还是长夜 2024-10-28 21:57:53

在此处输入图像描述

尝试以下代码:

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];
}

enter image description here

try this code:

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];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文