Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can do the following if you are using storyboard and autolayout (inspired by the first Answer)</p> <pre><code>UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; UIViewController *_vc = [sb instantiateViewControllerWithIdentifier:@"FloatingController"]; _anotherView = _vc.view; [_anotherView setTranslatesAutoresizingMaskIntoConstraints:NO]; [self.window addSubview: _anotherView]; [[VLBConstraintsGenerator sharedInstance] setWidth:200 forView:_anotherView inSuperView:_window]; [[VLBConstraintsGenerator sharedInstance] setHeight:200 forView:_anotherView inSuperView:_window]; [[VLBConstraintsGenerator sharedInstance] setLeading:0 forView:_anotherView inSuperView:_window]; [_anotherView setBackgroundColor:[UIColor grayColor]]; [[_anotherView layer] setBorderWidth:1]; [[_anotherView layer] setBorderColor:[UIColor yellowColor].CGColor]; [self.window makeKeyAndVisible]; [self.window bringSubviewToFront:_anotherView]; //not really needed here but it doesn't do any harm </code></pre> <p>all you need to do is to drag a view controller into you main storyboard with <strong>FloatingController</strong> as a storyboard ID </p> <p><strong>Additional Methods</strong></p> <pre><code>-(void)setWidth:(CGFloat )theWidth forView:(UIView *)theView inSuperView:(UIView *)theSuperView { assert([theSuperView isEqual:theView.superview]); NSLayoutConstraint *cn = [NSLayoutConstraint constraintWithItem:theView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:theWidth]; // [cn setPriority:999];//make it variable according to the orientation [theSuperView addConstraint:cn]; } -(void)setHeight:(CGFloat )theHeight forView:(UIView *)theView inSuperView:(UIView *)theSuperView { assert([theSuperView isEqual:theView.superview]); NSLayoutConstraint *cn = [NSLayoutConstraint constraintWithItem:theView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:theHeight]; [theSuperView addConstraint:cn]; } -(void)setLeading:(CGFloat )theLeading forView:(UIView *)theView inSuperView:(UIView *)theSuperView { assert([theSuperView isEqual:theView.superview]); NSLayoutConstraint *cn = [NSLayoutConstraint constraintWithItem:theView attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:theSuperView attribute:NSLayoutAttributeLeading multiplier:1 constant:theLeading]; [theSuperView addConstraint:cn]; } </code></pre>
    singulars
    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.
    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