简体   繁体   English

从CGPoints数组设置按钮帧(仅x和y位置)

[英]Setting Buttons frame(only x & y position) from array of CGPoints

1)I have an array of length 10 and named 'pointArrar'.This array contain CGPoints on its each index 1)我有一个长度为10的数组,名为'pointArrar'。该数组在每个索引上都包含CGPoints
2)Also I have 10 buttons. 2)我还有10个按钮。
Now I want to set Buttons frame(only x & y position) from array of CGPoints. 现在,我想从CGPoints数组中设置Buttons框架(仅x和y位置)。
I just want to know how to set buttons x and y position from CGPoint contained in array. 我只想知道如何从数组中包含的CGPoint设置按钮x和y的位置。

Well its very logical. 很好,这很合逻辑。

Lets say your array is like 可以说你的数组就像

NSArray * pointArrar = [NSArray arrayWithObjects:
                     [NSValue valueWithCGPoint:CGPointMake(5.5, 6.6)],
                     [NSValue valueWithCGPoint:CGPointMake(7.7, 8.8)],
                     nil];

Then to add to your various buttons you need to simply put all the points into a loop like 然后要添加到您的各种按钮,您只需要将所有点放入一个循环中,例如

for(int i=0; i<[pointArrar count] ; i++)
{
    NSValue *val = [pointArrar objectAtIndex:i];
    CGPoint p = [val CGPointValue];
    [Button setCenter:p];
}

Here all the points have been added to your button. 此处所有点均已添加到您的按钮中。 Hope this works for you :) 希望这对你有用:)

As i understand you want to use NSArray and it do not store any structures. 据我了解,您想使用NSArray并且它不存储任何结构。 So you can you NSValue to wrap you points and to add them to array. 因此,您可以使用NSValue包裹点并将其添加到数组中。 Here is an example.. 这是一个例子。

NSArray *points = [NSArray array];
// wrap your point using NSValue
NSValue *pointValue = [NSValue valueWithCGPoint:CGPointMake(x,y)];

[points addObject:pointValue];
/// ... add points

// get your point back...
CGPoint point = [[points objectAtIndex:index] CGPointValue];

button.frame = CGRectMake(point.x, point.y, button.frame.size.width, button.frame.size.height;

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

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