Saturday, 13 September 2014

Jogendra Singh

How do you create a UIImageView programmatically in swift


UIImageView class provides a view container for displaying either a single image or for animating a series of images. In this example we are going to display an image inside a frame that is smaller in size. With the help of ContentMode UIViewContentModeScaleAspectFit we can scale the content to fit the size of the view by maintaining the aspect ratio. Please see the reference Guide for other content modes that may help you set the image respective to the view frame. In this tutorial we are going to learn the following
  • Display an image on the screen
  • How to resize the image to fit the view frame
  • Animate a series of images

var imageViewObject :UIImageView
imageViewObject = UIImageView(frame:CGRectMake(0, 0, 100, 100));
imageViewObject.image = UIImage(named:"imageName.png")
self.view.addSubview(imageViewObject)

  • How to resize the image to fit the view frame
imageViewObject.contentMode = UIViewContentMode.ScaleToFill
  or
imageViewObject.contentMode = UIViewContentMode.ScaleAspectFit
or
imageViewObject.contentMode = UIViewContentMode.ScaleAspectFill

  • Animate a series of images
        UIView.animateWithDuration(1.0,
                         delay: 2.0,
                         options: .CurveEaseInOut | .AllowUserInteraction,
                 animations: {
                      self. imageViewObject.center = CGPoint(x: 75, y: 200)
                },
                 completion: { finished in
                       println("Bug moved left!")
        }) 

Jogendra Singh

About Jogendra Singh -

I'm Founder of Jogendra.Com. I love to share my bright ideas with the whole blogging community. I'm a good iPhone Application Developer. Apart from Blogging, I love to play Cricket and mobile games (Clash of clans).

Subscribe to this Blog via Email :

1 comments:

Write comments
Anonymous
AUTHOR
10 April 2022 at 20:28 delete

The King Casino Company - Ventureberg
It was born in 1934. The Company ventureberg.com/ offers luxury hotels, If you don't have a poker room in novcasino your house, then you'll 바카라사이트 find 출장안마 a 바카라 사이트 poker room in the

Reply
avatar