mac 相对布局
来源:互联网 发布:apache ab post请求 编辑:程序博客网 时间:2024/06/05 05:45
#import "NSView+TWFrame.h"@implementation NSView (TWFrame)- (void)setX:(CGFloat)x{ CGRect frame = self.frame; frame.origin.x = x; self.frame = frame;}- (CGFloat)x{ return self.frame.origin.x;}- (void)setY:(CGFloat)y{ CGRect frame = self.frame; frame.origin.y = y; self.frame = frame;}- (CGFloat)y{ return self.frame.origin.y;}// 返回高度-(CGFloat)height { return self.frame.size.height;}- (void)setHeight:(CGFloat)newheight{ CGRect newframe = self.frame; newframe.size.height = newheight; self.frame = newframe;}// 返回宽度- (CGFloat)width{ return self.frame.size.width;}// 设置宽度- (void)setWidth:(CGFloat)newwidth{ CGRect newframe = self.frame; newframe.size.width = newwidth; self.frame = newframe;}// 返回Y- (CGFloat)top{ return self.frame.origin.y;}- (void)setTop:(CGFloat)newtop{ CGRect newframe = self.frame; newframe.origin.y = newtop; self.frame = newframe;}// 返回X- (CGFloat)left{ return self.frame.origin.x;}- (void)setLeft:(CGFloat) newleft{ CGRect newframe = self.frame; newframe.origin.x = newleft; self.frame = newframe;}// 返回Y + Height- (CGFloat)bottom{ return self.frame.origin.y + self.frame.size.height;}- (void)setBottom:(CGFloat)newbottom{ CGRect newframe = self.frame; newframe.origin.y = newbottom - self.frame.size.height; self.frame = newframe;}// 返回X + width- (CGFloat)right{ return self.frame.origin.x + self.frame.size.width;}- (void)setRight:(CGFloat)newright{ CGFloat delta = newright - (self.frame.origin.x + self.frame.size.width); CGRect newframe = self.frame; newframe.origin.x += delta ; self.frame = newframe;}- (void)setSize:(CGSize)size{ CGRect frame = self.frame; frame.size = size; self.frame = frame;}- (CGSize)size{ return self.frame.size;}@end
使用autolayout
UIView *purpleView = [[UIView alloc] init]; purpleView.backgroundColor = [UIColor purpleColor]; // 禁止将 AutoresizingMask 转换为 Constraints purpleView.translatesAutoresizingMaskIntoConstraints = NO; [self.view addSubview:purpleView]; // 添加 width 约束 NSLayoutConstraint *widthConstraint = [NSLayoutConstraint constraintWithItem:purpleView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:0.0 constant:150]; [purpleView addConstraint:widthConstraint]; // 添加 height 约束 NSLayoutConstraint *heightConstraint = [NSLayoutConstraint constraintWithItem:purpleView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:0.0 constant:150]; [purpleView addConstraint:heightConstraint]; // 添加 left 约束 NSLayoutConstraint *leftConstraint = [NSLayoutConstraint constraintWithItem:purpleView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeft multiplier:1.0 constant:100]; [self.view addConstraint:leftConstraint]; // 添加 top 约束 NSLayoutConstraint *topConstraint = [NSLayoutConstraint constraintWithItem:purpleView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:1.0 constant:200]; [self.view addConstraint:topConstraint];
阅读全文
0 0
- mac 相对布局
- 相对布局
- 相对布局
- 相对布局
- 相对布局
- 相对布局
- 相对布局
- 相对布局
- 相对布局
- 相对布局
- 相对布局
- 相对布局
- 相对布局
- 相对布局
- 相对布局
- 相对布局
- Android 布局:相对布局
- android相对布局 相对对齐
- C语言:全局变量在多个文件中的使用方法
- 位运算基础
- 借助国内镜像库安装docker镜像
- JS 大坑 之 0.1+0.2 计算精度的问题
- tinyxml和tinyxml
- mac 相对布局
- macaca
- 颜色设置值
- SpringBoot
- NC57在前台,如何通过表头VO得到表体VO或者聚合的也行?
- tomcat 启动动重复Multiple Contexts have a path of "/xxxx"问题解决
- c++实现单/双链表
- vue 组件
- 【Maven+SSM】补充:写一个数据和对象Binding请求