Skip to content

Commit

Permalink
add category for UIView
Browse files Browse the repository at this point in the history
  • Loading branch information
[Tony] committed Jan 15, 2016
1 parent 55ca8d0 commit 27433fb
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
28 changes: 28 additions & 0 deletions UIView+GTView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// UIView+GTView.h
// CAAnimationTest
//
// Created by Tony on 16/1/15.
// Copyright © 2016年 JCH. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface UIView (GTView)

/**
* 为view(矩形)设置圆角
*
* @param corners 指定哪个角设置为圆角(可以是一、二、三,四个角的话用下面的方法)
* @param radii 圆角半径
*/
- (void)addCornerRadiusWithcorners:(UIRectCorner)corners AndRadii:(CGSize)radii;

/**
* 设置圆角矩形
*
* @param cornerRadius 圆角半径
*/
- (void)addCornerRadiusWithRadius:(CGFloat)cornerRadius;

@end
27 changes: 27 additions & 0 deletions UIView+GTView.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// UIView+GTView.m
// CAAnimationTest
//
// Created by Tony on 16/1/15.
// Copyright © 2016年 JCH. All rights reserved.
//

#import "UIView+GTView.h"

@implementation UIView (GTView)

- (void)addCornerRadiusWithcorners:(UIRectCorner)corners AndRadii:(CGSize)radii {
UIBezierPath *bezierPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:corners cornerRadii:radii];
CAShapeLayer *shapLayer = [[CAShapeLayer alloc]init];
shapLayer.path = bezierPath.CGPath;
self.layer.mask = shapLayer;
}

- (void)addCornerRadiusWithRadius:(CGFloat)cornerRadius {
UIBezierPath *bezierPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds cornerRadius:cornerRadius];
CAShapeLayer *shapLayer = [[CAShapeLayer alloc]init];
shapLayer.path = bezierPath.CGPath;
self.layer.mask = shapLayer;
}

@end

0 comments on commit 27433fb

Please sign in to comment.