subView.backgroundColor = [UIColor purpleColor]; [superView addSubview:subView]; //设置子视图的宽度随着父视图变化 subView.autoresizingMask 该属性表示autoresizingMask和autolayout两种方式的转换。这个属性对于在代码中生成的view来说默认是true,而对于IB中拖出来的view来说默认是false. 在实际的使用过程中,我还需要注意两点: 1.当我们设置这个属性为YES的时候,view的布局结果由AutoResizingMask,frame,center这些因素共同决定,如果再在其上添加AutoLayout
bigRadialProgressView.Center = new PointF (View.Center.X, View.Center.Y - 100); bigRadialProgressView.AutoresizingMask bigRadialProgressView.Frame.Left / 2, bigRadialProgressView.Center.Y); smallRadialProgressView.AutoresizingMask bigRadialProgressView.Frame.Right) / 2, bigRadialProgressView.Center.Y); tinyRadialProgressView.AutoresizingMask 30, bigRadialProgressView.Frame.Bottom + 80, View.Frame.Width - 60, 10); standardProgressView.AutoresizingMask startProgressButton.SetTitle ("Start Progress", UIControlState.Normal); startProgressButton.AutoresizingMask
一、通过代码进行布局 任何一个view都有autoresizingMask这个属性,通过这个属性可以设置当前view与其父视图的相对关系。 greenColor]; [view1 addSubview:view2]; [self.view addSubview:view1]; } 设置view2的自动布局属性如下: view2.autoresizingMask 设置如下: view2.autoresizingMask=UIViewAutoresizingFlexibleHeight; 效果如下: ? 如下设置: view2.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin; 效果如下: ? 这时子视图的左边是随父视图变化而可变的。 注意:这些自动布局的属性是可以叠加的,比如保持视图与父视图边距不变,如下设置: view2.autoresizingMask=UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight
key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <subviews key="<em>autoresizingMask</em>"/> <fontDescription key="fontDescription key="autoresizingMask"/> <fontDescription key="fontDescription key="autoresizingMask"/> <fontDescription key="fontDescription key="autoresizingMask"/> <fontDescription key="fontDescription" type=
下载命令 使用 Xib 使用 Autolayout OSX开发 @IBDesignable和@IBInspectable draw() 自定义NSView的背景颜色 使用 Xib 加载试图 设置 autoresizingMask 设置 autoresizingMask属性 我们设置一下 autoresizingMask属性。关于 autoresizingMask一些用法可以看一下下面的资料。 iOS开发-自动布局之autoresizingMask使用详解(Storyboard&Code) 我们设置高度自适应。 self.view.autoresizingMask = .viewHeightSizable 我们设置 SideMenuView的view的背景为rgb515151,方便我们进行查看。 ? self.view.autoresizingMask = [.viewWidthSizable,.viewHeightSizable] 这里说明一点,可选型不是如Objective-C 那样一般用|连接
那么autoresizingMask又是什么呢? autoresizingMask是一个枚举值,作用是自动调整子控件与父控件中间的margin(间距)或者子控件的宽高。 值得注意的是:autoresizingMask的枚举值是使用位移的形式给出的,这样设置的好处在于,当我们使用代码给某个视图设置autoresizingMask属性时,我们可以给autoresizingMask 不难发现,这样以位移的方式指定autoresizingMask枚举值,也契合了storyboard中可以给子控件设置多个方向的约束的情景。如下图: ? 注意:UIView的autoresizesSubviews属性为YES时(默认为YES),autoresizingMask才会生效。 也就是说,当我们想要利用autoresizingMask指定某个控件和其父控件的关系时候,必须autoresizesSubviews = YES。
解决办法:取消autoresizingMask 且通过xib创建的视图,self.view.bounds 不是屏幕那个尺寸 - (void)awakeFromNib { self.autoresizingMask view上时,尺寸设置self.view.bounds;会被拉伸,若不被拉伸用以下语句 scrollView.frame = self.view.bounds; scrollView.autoresizingMask
= [[UIImageView alloc] init]; img.image = [UIImage imageNamed:@"oatosLogo.png"]; img.autoresizingMask
self.webouterView.bounds, configuration: webConfiguration) self.webouterView.addSubview(myWebView) myWebView.autoresizingMask = UIView.AutoresizingMask.flexibleWidth let web_url = URL.init(string: weburl) myWebView.load(URLRequest.init
nonatomic) BOOL autoresizesSubviews; // 默认为YES,代表父控件会跟随子控件尺寸的变化而变化 @property(nonatomic) UIViewAutoresizing autoresizingMask UIViewAutoresizingFlexibleBottomMargin = 1 << 5 //与父视图上边间距固定,下边可变 }; 注意:UIView的autoresizesSubviews属性为YES时(默认为YES),autoresizingMask 才会生效,也就是说,当我们想要利用autoresizingMask指定某个控件和其父控件的关系时候,必须autoresizesSubviews = YES。
id="c22-O7-iKe"> <rect key="frame" x="0.0" y="0.0" width="480" height="272"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/> <subviews> > <rect key="frame" x="156" y="177" width="75" height="32"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/> <buttonCell key="cell
scaleToFill" id="1"> <rect key="frame" x="0.0" y="0.0" width="320" height="568" /> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES" /> <color key="backgroundColor
如下图,我们这个时候在“Show the Size inspector”面板上面就已经看不到AutoresizingMask的设置面板了。 先是粉色的父View,我们给它加上如下的AutoresizingMask。 给"雨天"的imageView加上如下AutoresizingMask 给"阴天"的imageView加上如下的AutoresizingMask ? 最后给我们的中间的Label加上AutoresizingMask 这个时候我们旋转一下屏幕,一切正常,View的排版都如我们所愿。 ? 注意这个时候右边还是AutoresizingMask的面板,因为这个时候Label还没有任何的constraint。
blurImageView.contentMode = UIViewContentMode.ScaleAspectFill //使图片充满ImageView blurImageView.autoresizingMask
UIView * presentedViewControllerView = [super presentedView]; presentedViewControllerView.autoresizingMask presentationWrapperView.bounds, UIEdgeInsetsMake(0, 0, -CORNER_RADIUS, 0))]; // autoresizingMask 这个属性 自动调整与父视图之间的边界距离 presentationRoundedCornerView.autoresizingMask = UIViewAutoresizingFlexibleWidth dimmingView.backgroundColor = [UIColor blackColor]; dimmingView.opaque = NO; dimmingView.autoresizingMask
UIView * presentedViewControllerView = [super presentedView]; presentedViewControllerView.autoresizingMask presentationWrapperView.bounds, UIEdgeInsetsMake(0, 0, -CORNER_RADIUS, 0))]; // autoresizingMask 这个属性 自动调整与父视图之间的边界距离 presentationRoundedCornerView.autoresizingMask = UIViewAutoresizingFlexibleWidth dimmingView.backgroundColor = [UIColor blackColor]; dimmingView.opaque = NO; dimmingView.autoresizingMask
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 40, 100, 100)]; imageView.autoresizingMask
initWithContentURL:url]; _moviePlayer.view.frame = self.view.bounds; _moviePlayer.view.autoresizingMask
2.1.1 外面四根线 表示子控件距离父控件的四周边距是否固定 2.1.2 里面两根线 子控件的宽高是否随着父控件的宽高变化 2.2 代码中使用Autoresizing AutoresizingMask redView.AutoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 3 Auto
translatesAutoresizingMaskIntoConstraints 默认为YES,也就是按照默认的autoresizingMask 进行计算;设置为NO之后,则可以使用更灵活的Autolayout lastView); // bottom = lastView}]; 不过对于我的项目来讲计算的太蛋疼了,于是偷了个懒,因为从pageview往里的每个view都是撑满父视图的,所以也就可以使用默认的autoresizingMask