Multiple unknown parameters in IOS
-(Void) setGradientColor :( UIColor *) beginColor transitionColor :( UIColor *) transitionColor,... NS_REQUIRES_NIL_TERMINATION;
// NS_REQUIRES_NIL_TERMINATION, used for non-nil end check during compilation
-(Void) setGradientColor :( UIColor *) beginColor transitionColor :( UIColor *) transitionColor ,...{
[Self. gradientColors addObject :( id) beginColor. CGColor];
// Define a pointer to the list of optional parameters
Va_list args;
// Obtain the address of the first optional parameter. The parameter list Pointer Points to the first optional parameter in the function parameter list.
Va_start (args, transitionColor );
If (transitionColor)
{
[Self. gradientColors addObject :( id) transitionColor. CGColor];
// Traverse the parameters in the parameter list and point the parameter list pointer to the next parameter in the parameter list
UIColor * nextArg;
While (nextArg = va_arg (args, UIColor *)))
{
[Self. gradientColors addObject :( id) nextArg. CGColor];
}
}
// End variable parameter acquisition (clear the parameter list)
Va_end (args );
}
[DrawCircleView setGradientColor: [UIColor purpleColor] transitionColor: [UIColor redColor], [UIColor blueColor], nil];