如何动态更改 UIButton 的位置 [英] How to change the position of a UIButton dynamically
问题描述
我在 IBOutletCollection 中有一组 31 个按钮,
I have a group of 31 buttons in a IBOutletCollection,
这是为了创建一个日历(即一个月中的天数,我必须根据工作日的第 1 天更改这些按钮的位置,看起来像日历.
This is to create a calendar (i.e) the number of days in a month, I have to change the position of these buttons depending on the 1st days week day, that looks like a calendar.
当我编写代码以在 Xcode 4.2 中实现相同功能时,我无法添加目标操作机制,因此我尝试使用 IBOutlet Collection 在 Interface Builder 中执行它.
I am not able to add target-action mechanism when I write code to implement the same in Xcode 4.2, so I tried do'g it in the Interface Builder using IBOutlet Collection.
但现在的问题是如何更改这些按钮的位置,每个按钮代表一个月中的某一天?
But now the question is how do I change the postion of these bottons each one representing the one day of the month?
推荐答案
你可以像这样改变位置:
You can change the position like so:
myButton.frame = CGRectMake( x, y, width, height );
例如
myButton.frame = CGRectMake( 20, 20, 100, 50 );
这篇关于如何动态更改 UIButton 的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!