ios - UIScrollView programmatically add buttons and scroll -


i'm new ios , objective-c. please little bit patient me.

the functionality in app, i'm trying develop, small scrolling toolbar, contains several buttons, state toggling buttons. there button above toolbar slides in , out toolbar. second functionality achieved successfully, using view whole setup , when slide button touch event animates whole view , down.

for scrollview, wanted add buttons programmatically, hence drew outlet class , tried adding self created button subview. cannot see button. nor can observe scrollview sliding.

the following way i'm adding button: also, total view above functionality less in size total view controller

uibutton *button = [[uibutton alloc] init];  button.titlelabel.text = @"hello";  [_scrolltop setcontentsize:self.view.frame.size];  [_scrolltop addsubview:button]; 

the 2 images down, hope, should understand functionality i'm trying develop. if aware of existence of similar functionality, please direct me.

closed

opened

edit: code totally is

    // //  hcilocationviewcontroller.m //  app2 // //  created ravi vooda on 13/03/13. //  copyright (c) 2013 housing.co.in. rights reserved. //  #import "hcilocationviewcontroller.h" #import "hciannotationviewcontroller.h"  @interface hcilocationviewcontroller ()  @property int widmap; @property bool showexploreoptions;   @end  @implementation hcilocationviewcontroller  - (id)initwithnibname:(nsstring *)nibnameornil bundle:(nsbundle *)nibbundleornil {     self = [super initwithnibname:nibnameornil bundle:nibbundleornil];     if (self) {         // custom initialization     }     return self; }  - (void)viewdidload {     [super viewdidload];     // additional setup after loading view.     _maplocationview.delegate = self;     mkpointannotation *annotation = [[hciannotationviewcontroller alloc]                                      initwithhouse:[self singlehome]];     [_maplocationview addannotation:annotation];     _widmap = 10000;      _showexploreoptions = no;      /*      uibutton *button = [uibutton buttonwithtype:uibuttontyperoundedrect];     [button addtarget:self                action:@selector(amethod:)      forcontrolevents:uicontroleventtouchdown];     [button settitle:@"show view" forstate:uicontrolstatenormal];     button.frame = cgrectmake(80.0, 210.0, 160.0, 40.0);//give values whatever want.     [_scrolltop addsubview:button];     */     [self addbuttonstoscrollview];  }  - (void)addbuttonstoscrollview {     nsinteger buttoncount = 4;      cgrect buttonframe = cgrectmake(5.0f, 5.0f, self.scrolltop.frame.size.width-10.0f, 40.0f);      (int index = 0; index <buttoncount; index++) {         uibutton *button = [[uibutton alloc]initwithframe:buttonframe];         [button addtarget:self action:@selector(buttonpressed:) forcontrolevents:uicontroleventtouchupinside];         [button settag:index+1];          nsstring *title = [nsstring stringwithformat:@"button %d",index+1];         [button settitle:title forstate:uicontrolstatenormal];          [self.scrolltop addsubview:button];         buttonframe.origin.y+=buttonframe.size.height+5.0f;     }      cgsize contentsize = self.scrolltop.frame.size;     contentsize.height = buttonframe.origin.y;     [self.scrolltop setcontentsize:contentsize];  }  - (void)buttonpressed:(uibutton *)button {     nslog(@"button pressed");      switch (button.tag) {         case 1:             //do             break;          default:             break;     } }  - (void)didreceivememorywarning {     [super didreceivememorywarning];     // dispose of resources can recreated. }  -(mkannotationview*) mapview:(mkmapview *)mapview viewforannotation:(id<mkannotation>)annotation {     nsstring *identifier = @"currdetailsidentifier";     mkpinannotationview *annotationview = (mkpinannotationview *)[_maplocationview dequeuereusableannotationviewwithidentifier:identifier];      if (annotationview == nil) {         annotationview = [[mkpinannotationview alloc]                           initwithannotation:annotation                           reuseidentifier:identifier];     } else {         annotationview.annotation = annotation;     }      annotationview.enabled = yes;     annotationview.canshowcallout = yes;     return annotationview; }  -(void) mapviewdidfinishloadingmap:(mkmapview *)mapview {      mkmaprect zoomrect = mkmaprectnull;     (id <mkannotation> annotation in mapview.annotations) {         mkmappoint annotationpoint = mkmappointforcoordinate(annotation.coordinate);         mkmaprect pointrect = mkmaprectmake(                                             annotationpoint.x - (_widmap / 2),                                             annotationpoint.y - (_widmap/2),                                             _widmap,                                             _widmap);         if (mkmaprectisnull(zoomrect)) {             zoomrect = pointrect;         } else {             zoomrect = mkmaprectunion(zoomrect, pointrect);         }     }     [mapview setvisiblemaprect:zoomrect animated:yes]; }  -(void) setmyhouse:(nsdictionary *)singlehouse {     self.singlehome = singlehouse; }   - (ibaction)toggleexploreoptionsview:(uibutton *)sender {      sender.selected = !sender.selected;      if (_showexploreoptions){         nslog(@"close options");         [uiview animatewithduration:0.2 animations:^{             _exploreview.frame = cgrectmake(_exploreview.frame.origin.x, _exploreview.frame.origin.y + _exploreoptionsview.frame.size.height, _exploreview.frame.size.width, _exploreview.frame.size.height + _exploreoptionsview.frame.size.height);         }];     }     else {         nslog(@"open options");         [uiview animatewithduration:0.2 animations:^{             _exploreview.frame = cgrectmake(_exploreview.frame.origin.x, _exploreview.frame.origin.y - _exploreoptionsview.frame.size.height, _exploreview.frame.size.width, _exploreview.frame.size.height - _exploreoptionsview.frame.size.height);         }];     }     _showexploreoptions = !_showexploreoptions; } @end 

if understood question correctly need have view should show , collapse on button click event. when view shown, should have scrollable list of buttons. , asking show many buttons scrollview.

demo source code

- (void)addbuttonstoscrollview {     nsinteger buttoncount = 5;      cgrect buttonframe = cgrectmake(5.0f, 5.0f, self.scrolltop.frame.size.width-10.0f, 40.0f);      (int index = 0; index <buttoncount; index++) {         uibutton *button = [uibutton buttonwithtype:uibuttontyperoundedrect];         [button setframe:buttonframe];         [button addtarget:self action:@selector(buttonpressed:) forcontrolevents:uicontroleventtouchupinside];         [button settag:index+1];          nsstring *title = [nsstring stringwithformat:@"button %d",index+1];         [button settitle:title forstate:uicontrolstatenormal];          [self.scrolltop addsubview:button];         buttonframe.origin.y+=buttonframe.size.height+5.0f;     }      cgsize contentsize = self.scrolltop.frame.size;     contentsize.height = buttonframe.origin.y;     [self.scrolltop setcontentsize:contentsize];  }  - (void)buttonpressed:(uibutton *)button {     switch (button.tag) {         case 1:             //do             break;          default:             break;     } } 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -