更改Storyboard中已存在的UIView的宽度?迅速

时间:2021-12-06 10:42:09

I already have created a UIView in the storyboard and connected it as an outlet, with the name progressView In Swift, I want to be able to change the width of this view in a certain function, however, so far I have been unable to.

我已经在故事板中创建了一个UIView并将其作为插座连接,名称为progressView在Swift中,我希望能够在某个功能中更改此视图的宽度,但是,到目前为止,我一直无法做到。

I would really appreciate any help.

我真的很感激任何帮助。

1 个解决方案

#1


1  

I've just write an example , if your project is autolayout , you need to define width constraint for progressView , then you need to make an outlet connection from your constraint and then change this property at method

我刚刚写了一个例子,如果你的项目是autolayout,你需要为progressView定义宽度约束,那么你需要从你的约束中建立一个出口连接然后在方法中改变这个属性

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *ViewWidth;

in method:

 self.ViewWidth.constant =number;

#1


1  

I've just write an example , if your project is autolayout , you need to define width constraint for progressView , then you need to make an outlet connection from your constraint and then change this property at method

我刚刚写了一个例子,如果你的项目是autolayout,你需要为progressView定义宽度约束,那么你需要从你的约束中建立一个出口连接然后在方法中改变这个属性

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *ViewWidth;

in method:

 self.ViewWidth.constant =number;