سؤال

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?

هل كانت مفيدة؟

المحلول

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

نصائح أخرى

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

UIViewContentModeScaleAspectFit

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.

You should use:

Portrait Mode

yourImage.frame = CGRectMake (x start, y start, x width, y width); 

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top