I have a NSMutableArray
, called buttonContainer
that contains UIButton
s. The thing is I want to change the CGRectmake()
of every button with a new value, is there an easy way to do this?
I'm trying this but get errors:
[buttonContainer objectAtIndex: i].frame = CGRectmake(x,y,w,h);
The error I get is: property 'frame' not found on object of type 'id'.
A NSMutableArray
can contain any id
type, and the return type of objectAtIndex
is id
which does not has a frame
property. If your array contains only UIButton
then you can do this inside loop:
UIButton *button = (UIButton *) [buttonContainer objectAtIndex:i];
button.frame = CGRectMake(x, y, w, h);
What you really want to do is use IBOutletCollection
.
You declare them in your @interface files and add your buttons to this collection, and then you can run a method over each object in the collection.
You can see more details here
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.