ios - Changing frame of view loaded from Xib -


i trying change frame of custom view load xib.

here init method of view:

- (id)initwithusername:(nsstring*)username andcomment:(nsstring*)comment {      if (self) {         self = [[[nsbundle mainbundle] loadnibnamed:@"comment" owner:self options:nil]objectatindex:0];          self.username = username;         self.comment = comment;         nslog(@"created");         nslog(@"%@, %@",self.username, self.comment);          self.usernamebutton.tag = -1;          cgsize constraint = cgsizemake(240, 2000);         self.usernamebutton.backgroundcolor = [uicolor clearcolor];         cgsize sizeofusernametext = [self.username sizewithfont:[uifont fontwithname:@"opensans-light" size:12.0] constrainedtosize:constraint linebreakmode:uilinebreakmodewordwrap];          //color converted #161616 hex         [self.usernamebutton.titlelabel settextcolor:[staticmethods colorfromhexstring:@"#161616"]];         [self.usernamebutton settitle:[self.username stringbyappendingstring:@":"] forstate:uicontrolstatenormal];         [self.usernamebutton.titlelabel setfont:[uifont fontwithname:@"opensans-light" size:12.0]];         [self.usernamebutton setneedsdisplay];          //[self.usernamebutton addtarget:self.delegate action:@selector(usernamebuttonpressed:) forcontrolevents:uicontroleventtouchupinside];         //append appropriate amount usernames can seen , clickable         nsstring *indentstring = @" ";         cgsize sizeofwhitespaces = [indentstring sizewithfont:[uifont fontwithname:@"opensans-light" size:12.0] constrainedtosize:constraint linebreakmode:uilinebreakmodewordwrap];         while (sizeofwhitespaces.width < sizeofusernametext.width) {             sizeofwhitespaces = [indentstring sizewithfont:[uifont fontwithname:@"opensans-light" size:12.0] constrainedtosize:constraint linebreakmode:uilinebreakmodewordwrap];             indentstring = [indentstring stringbyappendingstring: @" "];          }         cgsize sizeofcomment = [comment sizewithfont:[uifont fontwithname:@"opensans-light" size:12.0] constrainedtosize:constraint linebreakmode:uilinebreakmodewordwrap];          self.commenttext.tag = -1;         self.commenttext.text = [indentstring stringbyappendingstring: self.comment];         self.commenttext.font = [uifont fontwithname:@"opensans-light" size:12.0];         [self.commenttext settextcolor:[staticmethods colorfromhexstring:@"#161616"]];      }      return self; } 

this method called view controller this:

- (void)viewdidload {     [super viewdidload];     for(int = 0; < self.usernames.count;i++){         commentview *view = [[commentview alloc]initwithusername:[self.usernames objectatindex:i] andcomment:[self.comments objectatindex:i]];         [view setdelegate: self];         [self.view addsubview:view];         view.frame = cgrectmake(0,100,320,100);       }      // additional setup after loading view nib. } 

now, line says view.frame = cgrectmake(0,100,320,100); try change views frame. i have tried putting code inside view's

- (id)initwithusername:(nsstring*)username andcomment:(nsstring*)comment

method body well, without luck.

so having trouble resizing view according preferences. view has same frame when presented in interface builder.

what doing wrong?

edit

i have tried putting above viewdidload body inside viewcontroller's viewwillappear body, without progress.

disabling "use autolayout" in .xib solved me.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -