Reputation: 161
I want return 2 arguments in my method -(CGFloat)
. I try many way but can't. Here is my code. I want return both of them "heightSpace" and "widthSpace".
-(CGFloat) spaceBetweenLedCenterWhenNumberLedIsKnown: (int) n andM: (int) m {
CGFloat heightSpace = (self.view.bounds.size.height - 2 * _heightMargin) / (n - 1);
CGFloat widthSpace = (self.view.bounds.size.width - 2 * _widtheMargin) / (m - 1);
return [self spaceBetweenLedCenterWhenNumberLedIsKnown:heightSpace andM:widthSpace];
}
I have solve my problems with CGSize. Here is my final code. Thank to Zaph.
-(CGSize) coutingSpaceBetweenLedInHeight: (int) height andWidth: (int) width {
CGFloat heightSpace = (self.view.bounds.size.height - 2 * _heightMargin) / (height - 1);
CGFloat widthSpace = (self.view.bounds.size.width - 2 * _widthMargin) / (width - 1);
//typedef struct CGSize CGSize;
return CGSizeMake(heightSpace, widthSpace);}
Upvotes: 1
Views: 58
Reputation: 112855
Return a CGSize
, that contains two CGFloats
named width
and height
.
The caller can easily obtain the two values.
struct CGSize { CGFloat width; CGFloat height; }; typedef struct CGSize CGSize;
Upvotes: 2