简体   繁体   English

UIView设置框架和设置中心未应用

[英]UIView set frame and set center not applied

I expect to change UIView (UISegmentedView to be more detailed) to change position but it's not applied: 我希望更改UIView(更详细的UISegmentedView)以更改位置,但未应用:

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.segmentedControl.frame = CGRectMake(0, 0, 3 * 75, 50); // not working
    self.segmentedControl.center = self.view.center; // not working


    [self.segmentedControl setWidth:75 forSegmentAtIndex:0]; // working
    [self.segmentedControl setWidth:75 forSegmentAtIndex:1]; // working
    [self.segmentedControl setWidth:75 forSegmentAtIndex:2]; // working
}

One more result it that segment #3 can't be clicked though it's enabled and the right part of segment #2 is not clickable too which makes me think there is control active area width limitation. 另一个结果是,虽然启用了段#3,但无法单击它,并且段#2的右侧部分也无法单击,这使我认为存在控件活动区域宽度限制。 The view is created in UIViewController inheritor and xib. 该视图是在UIViewController继承者和xib中创建的。

I've posted this as an answer so you can check it as valid. 我已将其发布为答案,因此您可以检查其是否有效。 For anyone having this problems, the first thing I would check is if autolayout is enabled on your view's interface builder. 对于有此问题的任何人,我首先要检查的是是否在视图的界面生成器上启用了自动布局。

Open your view in the Interface Builder. 在“界面生成器”中打开视图。 Now, on the utilities, show the file inspector. 现在,在实用程序上,显示文件检查器。 You will find a checkbox "Use Autolayout". 您会发现一个复选框“ Use Autolayout”。 If it's checked, try unchecking it to see if it solves your problem. 如果已选中,请尝试取消选中它是否可以解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM