(自动调整蒙版)具有固定高度的图像的灵活宽度 [英] ( Autoresizing mask ) flexible width of an image with fixed height

查看:175
本文介绍了(自动调整蒙版)具有固定高度的图像的灵活宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在玩iPhone界面,只使用代码而不使用IB。

I have been playing around with iPhone interface building using only code and not using IB.

现在我遇到了以下问题:

Now I'm facing the following problem:

如何将图像设置为具有基于其所在主视图的宽度,并使其具有例如两侧50像素的边距。 (它也应该与旋转一起使用,因此宽度应该是灵活的)。

How can I set an image to have a width based on the main view it is located on and to let it have a margin of for example 50 pixels on both sides. ( it should also work with rotation so the width should be flexible ).

我尝试用frame.size.width设置大小 - 例如50,但是当屏幕旋转时这不起作用。我尝试的另一件事是使用自动调整遮罩,但我并不完全理解它是如何工作的。

I have tried setting the size with frame.size.width - 50 for example but this doesn't work when the screen rotates. Another thing I tried is using the autoresizing masks but I'm not completely understanding how this works.

是否还需要为图像设置框架或完全是这样的被自动化面具推翻?如果它被推翻,我怎么能给图像一个固定的高度和一个灵活的宽度?

Does one still need to set a frame for an image or is this completely overruled by the autoresizing masks? And if it's overruled how can I give the image a fixed height and a flexible width?

我正在使用的书(高级iOS4编程)在这里不是很清楚我在网上找到的大多数例子都是针对界面构建者的。

The book I'm using ( advanced iOS4 programming ) is not very clear in this matter and most examples I find on the net are for interface builder.

感谢您的时间。

种类问候,
Jasper

Kind regards, Jasper

推荐答案

水平:


  • 调整大小,保持固定的左/右边距: UIViewAutoresizingFlexibleWidth

  • 保持大小和左边相同的距离: UIViewAutoresizingFlexibleRightMargin

  • 保持大小,保持居中: UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin

  • 保持大小与右边相同距离: UIViewAutoresizingFlexibleLeftMargin

  • Resize keeping fixed left/right margins: UIViewAutoresizingFlexibleWidth
  • Keep size and same distance from the left: UIViewAutoresizingFlexibleRightMargin
  • Keep size, stay centered: UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin
  • Keep size and same distance from the right: UIViewAutoresizingFlexibleLeftMargin

垂直:


  • 调整大小,保持固定的上/下边距: UIViewAutoresizingFlexibleHeight

  • 保持大小和距离顶部相同的距离: UIViewAutoresizingFlexibleBottomMargin

  • 保持大小,保持居中: UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin

  • 保持大小与底部距离相同: UIViewAutoresizingFlexibleTopMargin

  • Resize keeping fixed top/bottom margins: UIViewAutoresizingFlexibleHeight
  • Keep size and same distance from the top: UIViewAutoresizingFlexibleBottomMargin
  • Keep size, stay centered: UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin
  • Keep size and same distance from the bottom: UIViewAutoresizingFlexibleTopMargin

将第一部分中的一部分与第二部分中的一部分合并为 | 。例如,要让它水平调整大小并保持与顶部垂直相同的大小和距离,您可以使用 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin

Combine one from the first section with one from the second with a |. For example, to have it resize horizontally and keep the same size and distance from the top vertically, you'd use UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin.

您可以使用其他组合来做一些更棘手的事情,但这些是基础知识。

You can use other combinations to do some more tricky things, but those are the basics.

这篇关于(自动调整蒙版)具有固定高度的图像的灵活宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆