rainbow.m
#import "RainBow.h"
@implementation RainBow
{
Nsarray * _colorarray;
}
-(instancetype) initWithFrame: (cgrect) frame withnum: (nsinteger) num{
self =[superinitwithframe: frame];
if (self) {
//1> Loading Data
[self_loaddata];
num=num<=_colorarray. countnum:_colorarray. Count;
self. BackgroundColor=[uicolorwhitecolor];
//2> loading a child view
for (int i=0; i<num;i++) {
UIView * view=[[UIViewalloc]initwithframe:cgrectmake(0, I *Ten,self. frame. size. width,ten)];
View. backgroundcolor=_colorarray[i];
[selfaddsubview: view];
}
//3> to redefine the height of the current parent view
Frame. size. height=ten*num;
Self. frame=frame;
}
returnself;
}
Appdelegate.m
#import "AppDelegate.h"
int count =0;
@interfaceappdelegate ()
@end
@implementation appdelegate
-(BOOL) Application: (uiapplication *) application didfinishlaunchingwithoptions: ( Nsdictionary *) launchoptions {
UIWindow * window = [[uiwindowalloc]initwithframe: [UIScreen mainscreen]. Bounds];
window. BackgroundColor = [uicolorwhitecolor];
Self. window = window;
[self. window makekeyandvisible];
Jrrainbow * view=[[jrrainbowalloc]initwithframe:cgrectmake(375 /2.0-2.0, (+) withnum: 8];
View. tag=8;
[Self. window addsubview: view];
}
OC UI input number n create n Rainbow IMP