更改UISegmentedControl的高度

更改UISegmentedControl的高度

本文介绍了更改UISegmentedControl的高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用此代码更改 UISegmentedControl 的高度:

I am trying to change height of UISegmentedControl using this code:

CGRect frame= mySegmentedControl.frame;
[mySegmentedControl setFrame:CGRectMake(frame.origin.x, frame.origin.y, frame.size.width, fNewHeight)];

但它不工作。有任何想法为什么?如果我在界面生成器中取消选中分段控件的使用自动布局功能,但是由于某些原因,分段控件中的项目将无法点击,它实际上可以工作...

But it does not work. has anyone idea why? It actually works, if I un-check the "Use Autolayout" feature of the segmented control in interface builder, but then the items in the segmented control become not clickable for some reasons...

这是旁边的问题,我仍然没有找到一个简单的方法添加多行文本到 UISegmentedControl (任何帮助

This is next to the issue, that I still didn't find an easy way to add multiple lines of text to the UISegmentedControl (any help here would also be appreciated).


推荐答案

>在iOS中展开视图实际上涉及3个因素
1. autolayout(自iOS6起可用)
2. setFrame
3.自动恢复掩码

Laying out views in iOS actually concerning 3 factors1. autolayout (avaliable since iOS6)2. setFrame3. autoreiszing mask

对于你的情况,

autolayout将帮助计算UIView所需的框架(基于NSLayouConstraints),然后布局它们。

autolayout will help to calculate the required frame (based on the NSLayouConstraints)for that UIView then lay them out.

所以在界面生成器中,如果启用autolayout,界面生成器会为该UIView生成NsLayoutConstraints。
如果禁用autolayout,构建器会为您生成一个框架UIView。

So in the interface builder, if you enable "autolayout", the interface builder is generating NsLayoutConstraints for that UIView.if you disable "autolayout" , the builder is generating a frame for you UIView.

假设您必须使用autolayout,您必须在正确的时间调整UISegmentedControl的大小。

Assuming you have to use autolayout, you have to resize your UISegmentedControl in a correct timing

- (void)viewDidLayoutSubview

这是关于视图生命周期。为了简化,它是:

It's about the view life cycle. To simplify it, it's like:

updateConstraints - > layout(你最好观看相关的WWDC会议视频的细节)

updateConstraints -> layout (You better watch related WWDC Session Videos for details)

您无法更改框架,因为此流程:

You can't change the frame because this flow:

通过代码设置新框架 - >查看句柄约束和计算(为UISegmentedControl生成另一个框架) >做布局

set new frame by code -> view handle constraints and calculation(generating an other frame for the UISegmentedControl) -> do the layout

对不起,这个组织不好的答案。

Sorry for this not-well-organised answer.

这篇关于更改UISegmentedControl的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 22:09