0

我正在学习Objective-c几个月,所以我是初学者。

我有一个图像(vertical gradient) 253px x 80px。我想把它延伸到screen width.

我怎样才能UIImageView * 1024( or 768) x 80px用这个图像?

4

5 回答 5

3

用于确定视图在其边界更改时如何布置其内容的标志。@property(nonatomic) UIViewContentMode contentMode

UIViewContentModeScaleAspectFit

于 2011-04-28T11:18:47.030 回答
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];
于 2011-04-28T11:30:39.243 回答
0

一种解决方案是调用:

imageView.transform = CGAffineTransformMakeScale( 1.5, 1);

这将在 x 轴上将图像拉伸 1.5 倍,但保留 y 轴尺寸。

于 2013-01-03T20:13:51.757 回答
0

您还可以查看有关 UIImage 方法的文档:

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

这使您可以制作可以使单个小图形适应各种尺寸和角色的图像。@Chugaister 的建议。

于 2011-04-28T13:56:35.263 回答
0

你应该使用:

人像模式

yourImage.frame = CGRectMake (x start, y start, x width, y width); 
于 2011-04-28T13:48:39.063 回答