您的位置:首页 > 移动开发 > IOS开发

iOS 圆角跟随屏幕尺寸变化,字体跟随屏幕尺寸变化

2016-06-28 15:54 253 查看
1.先写一下字体跟随屏幕尺寸变化

               label.adjustsFontSizeToFitWidth = Yes;

一句话就OK了字体会根据你的label的大小自行变化

2.下面是图片切圆角跟随屏幕尺寸变化 在collectionView的每个item样式中做过效果很不错

之前我们常用的 
.layer.cornerRadius = 

   .layer.masksToBounds = YES;

但是这种设置出来的数字无法跟随屏幕尺寸变化

所以可以试试以下步骤

    首先你需要导入  <AVFoundation/AVFoundation.h>文件   

_productImg.frame =
CGRectMake(0,
0, layoutAttributes.size.width,
layoutAttributes.size.width);

UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:_productImg.bounds byRoundingCorners:UIRectCornerAllCorners cornerRadii:_productImg.bounds.size];

    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];

    //
设置大小

    maskLayer.frame = _productImg.bounds;

    //
设置圆形样子

    maskLayer.path = maskPath.CGPath;

    _productImg.layer.mask = maskLayer;

这样图片所切得圆角就会跟随你的屏幕尺寸变化了, 而且这种方法对内存的消耗少,渲染快速.

    
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息