如何使用UIImageView(iPhone Dev。)?
-
26-10-2019 - |
题
我正在学习Objective-C几个月,所以我是初学者。
我有图像 (vertical gradient)
253px x 80px
. 。我想把它伸到 screen width
.
我该怎么做 UIImageView * 1024( or 768) x 80px
有这个图像吗?
解决方案
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];
其他提示
一个用于确定视图的标志在界限变化时如何显示其内容。 @property(非原子)uiviewContentMode contentmode
UiviewContentModescaleaspectFit
您还可以查找有关UIImage方法的文档:
- (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCapHeight
这使您可以制作可以使单个小图形适应各种尺寸和角色的图像。 @chugaister的建议。
您应该使用:
肖像模式
yourImage.frame = CGRectMake (x start, y start, x width, y width);
一种解决方案是致电:
imageView.transform = CGAffineTransformMakeScale( 1.5, 1);
这将在X轴上将图像扩展为1.5,但保留Y轴尺寸。
不隶属于 StackOverflow