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...
frame
then setting the origin to (0,0) perhaps you should have just retrieved itsbounds
in the first place. Difference between frame and bounds seems oft misunderstood. – RobPimage
you set on the button. Verify thatimage
is REALLY aUIImage
and not actually anNSString
. – rmaddyimage
for example? – Abhi Beckert