开发者

Put small images on the top of UIImageView?

I've got a UIImageView in a page that gets its image from the Interface bui开发者_开发技巧lder 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.


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


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


Put small images on the top of UIImageView?

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜