美文网首页
剪切iOS开发中的圆角

剪切iOS开发中的圆角

作者: LennonLin | 来源:发表于2016-08-03 15:14 被阅读148次
  • 为了剪切项目各种姿势的圆角,也为了让自己不要太懒了

介绍

  • 剪切有layer层控件的圆角,上下左右全部.单个圆角为去实现
  • 代码.h:
#import <UIKit/UIKit.h>

/**定义剪切的类型*/
typedef NS_ENUM(NSInteger, LXKShearRoundCornersType) {
    LXKShearRoundCornersTypeTop       = 1 << 0,
    LXKShearRoundCornersTypeBottom    = 1 << 1,
    LXKShearRoundCornersTypeLeftRight = 1 << 2,
    LXKShearRoundCornersTypeLeft      = 1 << 3,
    LXKShearRoundCornersTypeAll       = 1 << 4,
};

/**
 *  剪切有layer的圆角 可以上下左右的剪切
 */
@interface LXKShearRoundCorners : NSObject

/**
 *  剪切圆角
 *
 *  @param layer       CALayer
 *  @param type        枚举type
 *  @param radiusSize  radiusSize
 */
+ (void)ShearRoundCornersWidthLayer:(CALayer *)layer type:(LXKShearRoundCornersType )type radiusSize:(CGFloat)radiusSize;

@end
  • 代码.m:
#import "LXKShearRoundCorners.h"

@implementation LXKShearRoundCorners

/**
 *  剪切圆角
 *
 *  @param layer CALayer
 *  @param type  枚举type
 *  @param size  size
 */
+ (void)ShearRoundCornersWidthLayer:(CALayer *)layer type:(LXKShearRoundCornersType)type radiusSize:(CGFloat)radiusSize; {
    UIBezierPath *maskPath;
    if (type == LXKShearRoundCornersTypeTop) {
        maskPath = [UIBezierPath bezierPathWithRoundedRect:layer.bounds
                                         byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerTopRight)
                                               cornerRadii:CGSizeMake(radiusSize, radiusSize)];
    } else if (type == LXKShearRoundCornersTypeBottom) {
        maskPath = [UIBezierPath bezierPathWithRoundedRect:layer.bounds
                                         byRoundingCorners:(UIRectCornerBottomLeft  | UIRectCornerBottomRight)
                                               cornerRadii:CGSizeMake(radiusSize, radiusSize)];
    }  else if (type == LXKShearRoundCornersTypeLeftRight) {
        maskPath = [UIBezierPath bezierPathWithRoundedRect:layer.bounds
                                         byRoundingCorners:(UIRectCornerTopRight   | UIRectCornerBottomRight)
                                               cornerRadii:CGSizeMake(radiusSize, radiusSize)];
    }else if (type == LXKShearRoundCornersTypeLeft) {
        maskPath = [UIBezierPath bezierPathWithRoundedRect:layer.bounds
                                         byRoundingCorners:(UIRectCornerTopLeft   | UIRectCornerBottomLeft)
                                               cornerRadii:CGSizeMake(radiusSize, radiusSize)];
    }else if (type == LXKShearRoundCornersTypeAll) {
        maskPath = [UIBezierPath bezierPathWithRoundedRect:layer.bounds
                                         byRoundingCorners:UIRectCornerAllCorners
                                               cornerRadii:CGSizeMake(radiusSize, radiusSize)];
    }
    
    CAShapeLayer *maskLayer = [CAShapeLayer layer];
    maskLayer.frame = layer.bounds;
    maskLayer.path = maskPath.CGPath;
    layer.mask = maskLayer;
    [layer setMasksToBounds:YES];
}

@end

参考地址

相关文章

  • 剪切iOS开发中的圆角

    为了剪切项目各种姿势的圆角,也为了让自己不要太懒了 介绍 剪切有layer层控件的圆角,上下左右全部.单个圆角为去...

  • 视图指定位置圆角

    mark:iOS开发之指定UIView的某几个角为圆角ios中设置view固定方向的圆角 iOS View 指定圆...

  • iOS开发-使用UIBezierPath剪切视图圆角

    注:直接调用下面的方法即可,但是下面的方法必须在视图完成了布局之后再调用,否则将会看不到被剪切的视图!!! Swi...

  • 在StoryBoard中设置圆角,边框宽度等

    在iOS开发中,很多时候我们需要设置圆角,下面就介绍一种用storyBoard开发快速设置圆角的方式,废话不多说,...

  • iOS 圆角问题

    一般在iOS开发的过程中这样设置圆角 亲测在TableView 中一屏60个圆角, iOS 9.0 之后FPS能保...

  • ###iOS开发之UIView的指定角为圆角

    iOS开发之UIView的指定角为圆角 在开发中,当一个UIView需要4个角都是圆角的时候我们可以通过Corne...

  • 关于UIView切圆角的两种方式

    在 iOS App 开发中,切圆角的场景有很多。很多图片或者 UIView 都需要切圆角。 切圆角的方式一般有两种...

  • canvas 绘制带四周阴影效果的圆角图片

    绘制带四周阴影效果的圆角图片 想要绘制圆角图片一可以先绘制出圆角矩形,然后对画布进行剪切clip,这样在剪切过的画...

  • iOS-UIImageView圆角设置

    iOS开发中图片圆角设置是最常见的需求,圆角符合人类视觉安全体验,让人感觉舒适,设置圆角也是非常简单,有五种方式来...

  • UIView,UIButton,UIImageView等设立

    UIView,UIButton,UIImageView等设置圆角,设置阴影,设置边框的方法 在iOS开发中,任何可...

网友评论

      本文标题:剪切iOS开发中的圆角

      本文链接:https://www.haomeiwen.com/subject/epiqsttx.html