0

I'm studying Objective-c for several months, so I'm beginner.

I have an image (vertical gradient) 253px x 80px. And I want to stretch it to the screen width.

How can I make UIImageView * 1024( or 768) x 80px with this image?

User_1191
  • 981
  • 2
  • 8
  • 24
demon9733
  • 1,054
  • 3
  • 13
  • 35

5 Answers5

3

A flag used to determine how a view lays out its content when its bounds change. @property(nonatomic) UIViewContentMode contentMode

UIViewContentModeScaleAspectFit

Chugaister
  • 364
  • 4
  • 12
1
CGRect myImageRect = CGRectMake(0.0f, 0.0f, self.view.frame.size.width, 80.0f); 
UIImageView *myImage = [[UIImageView alloc] initWithFrame:myImageRect]; 
[myImage setImage:[UIImage imageNamed:@"gradient-253x80.png"]]; 
[self.view addSubview:myImage];
Jano
  • 62,815
  • 21
  • 164
  • 192
0

One solution would be to call:

imageView.transform = CGAffineTransformMakeScale( 1.5, 1);

This will stretch the image by a factor of 1.5 on the x axis, but retain y axis dimensions.

fearphage
  • 16,808
  • 1
  • 27
  • 33
0

You should use:

Portrait Mode

yourImage.frame = CGRectMake (x start, y start, x width, y width); 
Luke
  • 11,426
  • 43
  • 60
  • 69
Cagatay VASFI
  • 55
  • 1
  • 1
  • 8
0

You can also look up the documentation on UIImage's method:

- (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCapHeight

This allows you to make images that can adapt a single small graphic to a variety of sizes and roles. @Chugaister's suggestion.

Dancreek
  • 9,524
  • 1
  • 31
  • 34