如何根据不同的形状拼贴图像

如何在iPhone中进行图像拼贴。 我已经给出了图像,底部有不同的形状,根据这些形状我想改变图像。 所以请帮助我任何一个。 这将是非常感谢,我会很感激你的努力和帮助。 非常感谢…….

我已经试过这些链接如何使一个视图重新调整在iOS的照片拼贴画中的滑动?

在这里输入图像说明

我只是把我的逻辑。

  • 你的视图已经显示4个图像(具有不同的形状),所以你需要在.h文件中取4个UIImageView ,并且在.h文件中有一个UIView名称是ImgContainerView
  • 确保你的所有button都有相同的操作方法,并把所有的button都给它的标签。 比如每个button的方法名都是

    – (void)buttonMethodName:(UIButton *)发件人

  • 那么你需要创build一个方法名是,

    – (void)setUpimagesByselectedButton:(int)buttonTag

在button的操作方法中调用此方法,例如

 -(void) buttonMethodName:(UIButton *) sender { [self setUpimagesByselectedButton:sender.tag]; // pass button's tag as parameter. } 

现在在方法中,

 -(void)setUpimagesByselectedButton:(int) buttonTag { // first you need to remove all subview of ImgContainerView if(self.ImgContainerView) { for(UIView *subview in self.ImgContainerView.subviews) [subview removeFromSuperview]; [self.ImgContainerView removeFromSuperview]; self.ImgContainerView = nil; } // Then re-create ImgContainerView with background color is white; // add all UIImageView as subView of ImgContainerView; // and then set FRAME of your UIImageView base on selected button's tag such like. if(buttonTag == 1)// for ex. i take 1, here you write your button's tag. self.imageView1.frame.... // create one by one imageView and set it's frame by put condition as above // your UIImageView's contentMode should be UIViewContentModeScaleAspectFill or UIViewContentModeCenter; } 

当你点击任何button,每次ImgContainerView被重新创build与它的特定形状。