hi new ios programming. writing ios application , implemented few uibuttons. have set properties these buttons. instead of writing repetitive code each button, implemented separate method set properties. code given below
-(void)abc{ _xcord = self.view.bounds.size.width/2.0f; _ycord = self.view.bounds.size.height/2.0f; [self setbuttonproperties:_def]; // def ivar uibutton _xcord+=50; _ycord+=50; [self setbuttonproperties:_ghi]; // ghi ivar uibutton} set button properties given below
- (void)setbuttonproperties:(uibutton *)button{ button = [uibutton buttonwithtype:uibuttontypecustom]; button.frame = cgrectmake(_xcord, _ycord, 50, 50); button.clipstobounds = yes; button.layer.cornerradius = 50/2.0f; button.layer.bordercolor = [uicolor redcolor].cgcolor; button.layer.borderwidth = 2.0f; [self.view addsubview:button]; } here button added view not reflected ivar uibutton.when implement target methods button actions respective methods of buttons not called. there way send uibutton reference or other way can achieve same setbuttonproperties method set ivar uibutton properties.
thanks in advance
you can pass ivar reference (adding & ivars , adjusting setbuttonproperties method). since code don't need suggest code returns button pravin tate suggests.
-(void)abc{ _xcord = self.view.bounds.size.width/2.0f; _ycord = self.view.bounds.size.height/2.0f; [self setbuttonproperties:&_def]; // def ivar uibutton _xcord+=50; _ycord+=50; [self setbuttonproperties:&_ghi]; // ghi ivar uibutton} nslog(@"foo"); } - (void)setbuttonproperties:(uibutton * __strong *)button{ *button = [uibutton buttonwithtype:uibuttontypecustom]; (*button).frame = cgrectmake(_xcord, _ycord, 50, 50); (*button).clipstobounds = yes; (*button).layer.cornerradius = 50/2.0f; (*button).layer.bordercolor = [uicolor redcolor].cgcolor; (*button).layer.borderwidth = 2.0f; [self.view addsubview:*button]; }
Comments
Post a Comment