简体   繁体   English

快速移动NSButton

[英]Move NSButton swift

I have a NSButton named round, and I need to change its position according to the previous position, eg move it 100 pixels to the right. 我有一个名为round的NSButton ,我需要根据先前的位置更改其位置,例如,将其向右移动100像素。 How to do that? 怎么做? I'm new to swift, so any help will be appreciated 我是新手,所以我们将不胜感激

You need to edit the frame of the button, basically changing the x coordinate with 100 pixels to the right, that means increasing it by 100. See the code below 您需要编辑按钮的框架,基本上将x坐标更改为右侧100像素,这意味着将其增加100。请参见下面的代码

var button  = NSButton(frame: NSRect(x: 0, y: 0, width: 100, height: 50));
var frame = button.frame
frame.origin.x += 100
button.frame = frame

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

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