IOS开发之屏幕适
来源:互联网 发布:日本tpp知乎 编辑:程序博客网 时间:2024/06/04 23:19
开发适配是必不可少的一个步骤,下面总结一下适配的方法
1. 根据屏幕宽/高不同,来进行适配
(1) 宏定义
// collectionView 的x的值
#define CollectionViewX 0
// collectionView 的y的值
#define CollectionViewY 120
// segment的 y 的值
#define SegmentY 75
// 的宽
#define SegmentWidth 200
// 的高
#define SegmentHeight 40
- (void)viewDidLoad {
[superviewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColorwhiteColor];
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayoutalloc]init];
if (self.view.frame.size.width == 375) {
flowLayout.itemSize =CGSizeMake(150,100);
}
if (self.view.frame.size.width == 320) {
flowLayout.itemSize =CGSizeMake(120,80);
}
if (self.view.frame.size.width == 414) {
flowLayout.itemSize =CGSizeMake(160,110);
}
flowLayout.minimumInteritemSpacing =10;
flowLayout.minimumLineSpacing =10;
flowLayout.sectionInset =UIEdgeInsetsMake(10,30,50,30);
self.collectionView = [[UICollectionViewalloc]initWithFrame:CGRectMake(CollectionViewX,CollectionViewY,self.view.frame.size.width,self.view.frame.size.height - CollectionViewY)collectionViewLayout:flowLayout];
self.collectionView.backgroundColor = [UIColorwhiteColor];
[self.viewaddSubview:self.collectionView];
self.collectionView.delegate =self;
self.collectionView.dataSource =self;
}
2.宏定义屏幕的尺寸, 用宏定义FRAME尺寸与原来坐标尺寸相除得到比例,进行适配, 有点恶心这个
(1)宏定义
#define X 5
#define Y 5
#define W 100
#define H 150
#define FRAME [[UIScreen mainScreen] bounds]
- (void)createSubView
{
CGRect frame =CGRectMake(FRAME.size.width/75,FRAME.size.height/133.6,FRAME.size.width/3.75,FRAME.size.height/4.453);
self.imageView1 = [[UIImageViewalloc]initWithFrame:frame];
self.imageView1.backgroundColor = [UIColorwhiteColor];
[self.contentViewaddSubview:self.imageView1];
frame =self.imageView1.frame;
frame.origin.x += (frame.size.width + FRAME.size.width/37.5);
frame.size.width =FRAME.size.width/9.375;
frame.size.height =FRAME.size.height/16.7;
self.categorylabel1 = [[UILabelalloc]initWithFrame:frame];
self.categorylabel1.backgroundColor = [UIColorwhiteColor];
self.categorylabel1.text =@"类型";
[self.contentViewaddSubview:self.categorylabel1];
frame =self.categorylabel1.frame;
frame.origin.x += (FRAME.size.width/37.5 + frame.size.width);
frame.size.width =FRAME.size.width/1.875;
self.categoryLabel2 = [[UILabelalloc]initWithFrame:frame];
self.categoryLabel2.backgroundColor = [UIColorwhiteColor];
[self.contentViewaddSubview:self.categoryLabel2];
frame =self.categorylabel1.frame;
frame.origin.y += (frame.size.height + FRAME.size.height/66.8);
self.authorLabel1 = [[UILabelalloc]initWithFrame:frame];
self.authorLabel1.backgroundColor = [UIColorwhiteColor];
self.authorLabel1.text =@"作者";
[self.contentViewaddSubview:self.authorLabel1];
frame =self.categoryLabel2.frame;
frame.origin.y += (FRAME.size.height/66.8 + frame.size.height);
self.authorLabel2 = [[UILabelalloc]initWithFrame:frame];
self.authorLabel2.backgroundColor = [UIColorwhiteColor];
[self.contentViewaddSubview:self.authorLabel2];
frame =self.authorLabel1.frame;
frame.origin.y += (frame.size.height + FRAME.size.height/66.8);
self.scoreLabel1 = [[UILabelalloc]initWithFrame:frame];
self.scoreLabel1.backgroundColor = [UIColorwhiteColor];
self.scoreLabel1.text =@"评分";
[self.contentViewaddSubview:self.scoreLabel1];
frame =self.authorLabel2.frame;
frame.origin.y += (frame.size.height + FRAME.size.height/66.8);
self.scoreLabel2 = [[UILabelalloc]initWithFrame:frame];
self.scoreLabel2.backgroundColor = [UIColorwhiteColor];
[self.contentViewaddSubview:self.scoreLabel2];
3.这个就比较简单了, 本例是在Iphone6的基础上做的适配,宽:375, 高:668, 即把宽高的比例算出来, 原坐标乘以这个比例就可以了,也就是X乘以宽的比例,Y乘以高的比例, 宽高分别乘以宽高的比例
(1)宏定义
#define W 150
#define H 40
#define W1 [[UIScreen mainScreen] bounds].size.width/375
#define H1 [[UIScreen mainScreen] bounds].size.height/668
- (void)viewDidLoad {
[superviewDidLoad];
// Do any additional setup after loading the view.
self.button1 = [UIButtonbuttonWithType:UIButtonTypeCustom];
self.button1.backgroundColor = [UIColorclearColor];
self.button1.frame =CGRectMake(25*W1,200*H1,W*W1, H*H1);
UIButton *button2 = [UIButtonbuttonWithType:UIButtonTypeCustom];
button2.backgroundColor = [UIColorclearColor];
button2.frame =CGRectMake(25*W1, (200 +H + 15)*H1,W*W1,H*H1);
[button2 setBackgroundImage:[UIImageimageNamed:@"5.png"]forState:UIControlStateNormal];
[
UIButton *button3 = [UIButtonbuttonWithType:UIButtonTypeCustom];
button3.backgroundColor = [UIColorclearColor];
button3.frame =CGRectMake(25*W1, (200 +2 *(H +15))*H1, W*W1,H*H1);
UIButton *button4 = [UIButtonbuttonWithType:UIButtonTypeCustom];
button4.backgroundColor = [UIColorclearColor];
button4.frame =CGRectMake(25*W1, (200 +3 *(H +15))*H1, W*W1,H*H1);
}
- IOS开发之屏幕适
- iOS开发 之 屏幕适配
- iOS开发之屏幕旋转
- iOS开发之屏幕旋转
- iOS开发之屏幕截图
- iOS开发UI系列之屏幕适配
- iOS开发之-屏幕适配相关小结-
- iOS开发 - 屏幕适配之纯代码
- iOS开发 - 屏幕适配之VFL语言
- 【转载】iOS开发之屏幕旋转
- iOS开发- 游戏屏幕适配(SpriteKit)
- iOS开发屏幕适配问题解决方案
- iOS开发 纯代码屏幕适配
- iOS开发--------屏幕尺寸适配
- iOS开发日志:多屏幕适配
- iOS开发 -- 屏幕旋转
- IOS开发 - 屏幕旋转
- iOS开发之App开发团队必须知道的 iOS 11 更新点几iPhoneX的屏幕适配
- LeetCode-Palindrome Partitioning
- 【Python】DNS域名轮循业务监控
- 博弈详解合集(巴什+威佐夫+尼姆)
- hdu 1597 二分查找
- SEAndroid安全机制中的进程安全上下文关联分析
- IOS开发之屏幕适
- 动画(三)(转场动画, 动画组)
- iOS 之UITapGestureRecognizer活学活用
- HDU 1159 Common Subsequence 最大公共子序列
- Java注解处理器
- SEAndroid安全机制对Android属性访问的保护分析
- CentOS 6/Linux 安装Mongodb 2.6.5
- 友盟反馈中发现的这样的问题,对下文没有考证,最终对2.3版本通过绕过Parserable 和 serializable方式解决的,留此只做备忘
- Linux内核驱动学习(四)----内存管理子系统