I am creating UIButton dynamically in the FOR loop as follows :
CGRect workingFrame = imgscrollView.frame;
workingFrame.origin.x = 0;
workingFrame.origin.y = 0;
for (int i=0 ; i < self.currentDetails.arrayOfImages.count ; i++)
{
UIButton *imageBtn = [[UIButton alloc] init];
[imageBtn setImage:image forState:UIControlStateNormal];
[imageBtn setUserInteractionEnabled:TRUE];
imageBtn.layer.cornerRadius = 8;
imageBtn.layer.borderWidth = 1;
imageBtn.layer.borderColor = [UIColor whiteColor].CGColor;
imageBtn.layer.masksToBounds = YES;
imageBtn.clipsToBounds = YES;
[imageBtn setContentMode:UIViewContentModeScaleAspectFill];
[imageBtn addTarget:self action:@selector(changeButtonImage:) forControlEvents:UIControlEventTouchUpInside];
[imageBtn setTag:i];
[imgscrollView addSubview:imageBtn];
imageBtn.frame = CGRectMake(workingFrame.origin.x+20, workingFrame.origin.y, 145, 140);
}
But at the time of setting its frame
imageBtn.frame = CGRectMake(workingFrame.origin.x+20, workingFrame.origin.y, 145, 140);
i am getting following error and it crashes :
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString size]: unrecognized selector sent to instance
I have searched for this but could not get the solution.
Please help me.
Thanks…
Best Answer
Size method is there for the classes that are in the image attached
Since you are using image here check whether you have a proper image instance.