iPhone 设置自动调整大小

标签 iphone objective-c ios

我正在尝试在导航栏的子类和分段控件上设置自动调整大小。我需要在代码中执行此操作,而不是界面生成器。

我想要与此接口(interface)设置等效的代码。

enter image description here

编辑:

我试过这个,但它不起作用。

[self.segmentedControl setAutoresizingMask: UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin];   

最佳答案

View Programming Guide笔记:

The flexible width and height constants [UIViewAutoresizingFlexibleHeight and UIViewAutoresizingFlexibleWidth] from the preceding figure have the same behavior as the width and size indicators in the Autosizing controls diagram. However, the behavior and use of margin indicators is effectively reversed. In Interface Builder, the presence of a margin indicator means that the margin has a fixed size and the absence of the indicator means the margin has a flexible size.



您希望底部、左侧和右侧边距固定(这是默认值),而顶部边距灵活。试试这个:
[self.segmentedControl setAutoresizingMask: UIViewAutoresizingFlexibleTopMargin];

关于iPhone 设置自动调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10376464/

相关文章:

ios - NSURLCache 不在 iOS 7 中存储缓存数据

ios - "Application validation was skipped"因为无法加载 "the bundle “ITunesSoftwareService””

ios - 如何编写一个关于如何在 Swift 5 中使用委托(delegate)的简单示例

ios - NSDateFormat dd/MM/yyyy 到 MM/dd/yyyy iOS

objective-c - 我将在哪里实现一个通用方法,供 3 ​​个不同的 View Controller 使用?

iphone - iOS 5 "Notification Center"API?

ios - 当导航栏的颜色在不同的 View Controller 之间发生变化时,如何更改后退按钮的颜色?

ios - 如何以编程方式显示键盘

ios - 将位置源从 GPS 切换到本地 `gpx` 文件

jQuery val() 打开键盘