Note that there are some explanatory texts on larger screens.

plurals
  1. POChanging frame of view loaded from Xib
    primarykey
    data
    text
    <p>I am trying to change the frame of my custom view which I load from a xib. </p> <p><strong>Here is my init method of the view:</strong></p> <pre><code>- (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 from #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 so that the usernames can be seen and clickable NSString *indentString = @" "; CGSize sizeOfWhitespaces = [indentString sizeWithFont:[UIFont fontWithName:@"OpenSans-Light" size:12.0] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap]; while (sizeOfWhitespaces.width &lt; 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; } </code></pre> <p><strong>This method is called from a view controller like this:</strong></p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; for(int i = 0; i &lt; 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); } // Do any additional setup after loading the view from its nib. } </code></pre> <p>Now, the line where it says <code>view.frame = CGRectMake(0,100,320,100);</code> is where i try to change the views frame. <strong>I have tried putting that code inside the view's</strong> </p> <p><code>- (id)initWithUserName:(NSString*)userName andComment:(NSString*)comment</code> </p> <p><strong>method body as well</strong>, without luck.</p> <p>So clearly I am having trouble resizing the view according to my preferences. The view has always the same frame as when it is presented in interface builder.</p> <p>What am I doing wrong?</p> <p><strong>EDIT</strong></p> <p>I have tried putting the above <code>viewDidLoad</code> body inside that viewcontroller's <code>viewWillAppear</code> body, without any progress.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload