ios - How to Call the Custom UIView from ViewController using Frame Size -


i want show customuiview viewcontroller.how call using frame?i getting confused in frame newbie. theme is,i want show loginviewkarnataka , usernamelabel in viewcontroller in y value 150. code

viewcontroller.m

loginviewkarnataka *loginview = [[loginviewkarnataka alloc]initwithframe:cgrectmake(0, 0, self.view.frame.size.width, 150)]; [self.view addsubview:loginview]; 

loginviewkarnataka(customuiview)

-(instancetype)initwithframe:(cgrect)frame {  self = [super initwithframe:frame]; nslog(@"frame==>>%f",frame); if (self) {     uilabel *usernamelabel = [[uilabel alloc]initwithframe:cgrectmake(20, 20, 100, 20)];     [usernamelabel settext:@"username"];     [usernamelabel settextcolor:[uicolor blackcolor]]; } } 

change viewcontroller code to

loginviewkarnataka *loginview = [[loginviewkarnataka alloc]initwithframe:cgrectmake(0, 50, self.view.frame.size.width, 150)]; [self.view addsubview:loginview]; 

in loginviewkarnataka view

-(instancetype)initwithframe:(cgrect)frame {  self = [super initwithframe:frame];  if (self)  {    [self setbackgroundcolor:[uicolor redcolor]];    uilabel *usernamelabel = [[uilabel alloc]initwithframe:cgrectmake(20, 20, 100, 20)];    [usernamelabel settext:@"username"];    [usernamelabel settextcolor:[uicolor blackcolor]];    [self addsubview:label];   }  return self; } 

in above code, adding label @ positions of x: 20, y: 20. print frame of view use following code.

    nslog(@"frame : %@",nsstringfromcgrect(self.view.frame)); 

to print size of view

    nslog(@"frame : %@",nsstringfromcgsize(self.view.frame.size)); 

Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -