Initial commit
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
//
|
||||
// UIButton+BBTButton.h
|
||||
// bangbangtang
|
||||
//
|
||||
// Created by guoyun3 on 16/5/9.
|
||||
// Copyright © 2016年 guoyun3. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
typedef NS_ENUM(NSUInteger, UKButtonEdgeInsetsStyle) {
|
||||
UKButtonEdgeInsetsStyleTop = 0, // image在上,label在下
|
||||
UKButtonEdgeInsetsStyleLeft = 1 << 1, // image在左,label在右
|
||||
UKButtonEdgeInsetsStyleBottom = 1 << 2, // image在下,label在上
|
||||
UKButtonEdgeInsetsStyleRight = 1 << 3 // image在右,label在左
|
||||
};
|
||||
|
||||
@interface UIButton(BBTButton)
|
||||
|
||||
/**
|
||||
* 设置button的titleLabel和imageView的布局样式,及间距
|
||||
*
|
||||
* @param style titleLabel和imageView的布局样式
|
||||
* @param space titleLabel和imageView的间距
|
||||
*/
|
||||
- (void)layoutButtonWithEdgeInsetsStyle:(UKButtonEdgeInsetsStyle)style imageTitleSpace:(CGFloat)space;
|
||||
|
||||
//倒计时
|
||||
- (void)startWithTime:(NSInteger)timeLine title:(NSString *)title countDownTitle:(NSString *)subTitle mainColor:(UIColor *)mColor countColor:(UIColor *)color;
|
||||
@end
|
||||
@@ -0,0 +1,173 @@
|
||||
//
|
||||
// UIButton+BBTButton.m
|
||||
// bangbangtang
|
||||
//
|
||||
// Created by guoyun3 on 16/5/9.
|
||||
// Copyright © 2016年 guoyun3. All rights reserved.
|
||||
//
|
||||
|
||||
#import "UIButton+BBTButton.h"
|
||||
|
||||
@implementation UIButton(BBTButton)
|
||||
-(void)layoutButtonForTitle:(NSString *)title
|
||||
titleFont:(UIFont *)titleFont
|
||||
image:(UIImage *)image
|
||||
gapBetween:(CGFloat)gap
|
||||
layType:(NSInteger)layType
|
||||
{
|
||||
switch (layType) {
|
||||
case 0:
|
||||
{
|
||||
//title---left ,image---right
|
||||
[self setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
|
||||
CGFloat image_width = image.size.width;
|
||||
|
||||
NSDictionary *attribute = @{NSFontAttributeName:titleFont};
|
||||
|
||||
CGSize titleSize = [title boundingRectWithSize:CGSizeMake(self.frame.size.width,MAXFLOAT)
|
||||
options:NSStringDrawingTruncatesLastVisibleLine |NSStringDrawingUsesLineFragmentOrigin |NSStringDrawingUsesFontLeading
|
||||
attributes:attribute
|
||||
context:nil].size;
|
||||
|
||||
CGFloat title_origin_x = (self.frame.size.width-image_width-gap-titleSize.width)/2 - image_width;
|
||||
CGFloat image_origin_x = title_origin_x + gap + titleSize.width+image_width;
|
||||
|
||||
[self setTitleEdgeInsets:UIEdgeInsetsMake(0,title_origin_x,0,0)];
|
||||
[self setImageEdgeInsets:UIEdgeInsetsMake(0,0,0,-image_origin_x-3)];
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
{
|
||||
//title---right ,image---left
|
||||
[self setImageEdgeInsets:UIEdgeInsetsMake(0,-gap/2,0,0)];
|
||||
[self setTitleEdgeInsets:UIEdgeInsetsMake(0,gap/2+10,0,0)];
|
||||
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
{
|
||||
//title---down ,image---up
|
||||
NSDictionary *attribute = @{NSFontAttributeName:titleFont};
|
||||
|
||||
CGSize titleSize = [title boundingRectWithSize:CGSizeMake(self.frame.size.width,MAXFLOAT)
|
||||
options:NSStringDrawingTruncatesLastVisibleLine |NSStringDrawingUsesLineFragmentOrigin |NSStringDrawingUsesFontLeading
|
||||
attributes:attribute
|
||||
context:nil].size;
|
||||
CGFloat title_origin_x = -image.size.width/2;
|
||||
CGFloat image_origin_x = titleSize.width/2;
|
||||
CGFloat image_origin_y = - (titleSize.height+gap)/2;
|
||||
CGFloat title_origin_y = (image.size.height+gap)/2;
|
||||
[self setImageEdgeInsets:UIEdgeInsetsMake(image_origin_y,image_origin_x,-image_origin_y,-image_origin_x)];
|
||||
[self setTitleEdgeInsets:UIEdgeInsetsMake(title_origin_y,title_origin_x,-title_origin_y,-title_origin_x)];
|
||||
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
- (void)layoutButtonWithEdgeInsetsStyle:(UKButtonEdgeInsetsStyle)style
|
||||
imageTitleSpace:(CGFloat)space
|
||||
{
|
||||
/**
|
||||
* 前置知识点:titleEdgeInsets是title相对于其上下左右的inset,跟tableView的contentInset是类似的,
|
||||
* 如果只有title,那它上下左右都是相对于button的,image也是一样;
|
||||
* 如果同时有image和label,那这时候image的上左下是相对于button,右边是相对于label的;title的上右下是相对于button,左边是相对于image的。
|
||||
*/
|
||||
|
||||
|
||||
// 1. 得到imageView和titleLabel的宽、高
|
||||
CGFloat imageWith = self.imageView.frame.size.width;
|
||||
CGFloat imageHeight = self.imageView.frame.size.height;
|
||||
|
||||
CGFloat labelWidth = 0.0;
|
||||
CGFloat labelHeight = 0.0;
|
||||
if ([UIDevice currentDevice].systemVersion.floatValue >= 8.0) {
|
||||
// 由于iOS8中titleLabel的size为0,用下面的这种设置
|
||||
labelWidth = self.titleLabel.intrinsicContentSize.width;
|
||||
labelHeight = self.titleLabel.intrinsicContentSize.height;
|
||||
} else {
|
||||
labelWidth = self.titleLabel.frame.size.width;
|
||||
labelHeight = self.titleLabel.frame.size.height;
|
||||
}
|
||||
|
||||
// 2. 声明全局的imageEdgeInsets和labelEdgeInsets
|
||||
UIEdgeInsets imageEdgeInsets = UIEdgeInsetsZero;
|
||||
UIEdgeInsets labelEdgeInsets = UIEdgeInsetsZero;
|
||||
|
||||
// 3. 根据style和space得到imageEdgeInsets和labelEdgeInsets的值
|
||||
switch (style) {
|
||||
case UKButtonEdgeInsetsStyleTop:
|
||||
{
|
||||
imageEdgeInsets = UIEdgeInsetsMake(-labelHeight-space/2.0, 0, 0, -labelWidth);
|
||||
labelEdgeInsets = UIEdgeInsetsMake(0, -imageWith, -imageHeight-space/2.0, 0);
|
||||
}
|
||||
break;
|
||||
case UKButtonEdgeInsetsStyleLeft:
|
||||
{
|
||||
imageEdgeInsets = UIEdgeInsetsMake(0, -space/2.0, 0, space/2.0);
|
||||
labelEdgeInsets = UIEdgeInsetsMake(0, space/2.0, 0, -space/2.0);
|
||||
}
|
||||
break;
|
||||
case UKButtonEdgeInsetsStyleBottom:
|
||||
{
|
||||
imageEdgeInsets = UIEdgeInsetsMake(0, 0, -labelHeight-space/2.0, -labelWidth);
|
||||
labelEdgeInsets = UIEdgeInsetsMake(-imageHeight-space/2.0, -imageWith, 0, 0);
|
||||
}
|
||||
break;
|
||||
case UKButtonEdgeInsetsStyleRight:
|
||||
{
|
||||
imageEdgeInsets = UIEdgeInsetsMake(0, labelWidth+space/2.0, 0, -labelWidth-space/2.0);
|
||||
labelEdgeInsets = UIEdgeInsetsMake(0, -imageWith-space/2.0, 0, imageWith+space/2.0);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// 4. 赋值
|
||||
self.titleEdgeInsets = labelEdgeInsets;
|
||||
self.imageEdgeInsets = imageEdgeInsets;
|
||||
}
|
||||
|
||||
- (void)startWithTime:(NSInteger)timeLine title:(NSString *)title countDownTitle:(NSString *)subTitle mainColor:(UIColor *)mColor countColor:(UIColor *)color{
|
||||
|
||||
// 倒计时时间
|
||||
__block NSInteger timeOut = timeLine;
|
||||
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
|
||||
dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
|
||||
// 每秒执行一次
|
||||
dispatch_source_set_timer(_timer, dispatch_walltime(NULL, 0), 1.0 * NSEC_PER_SEC, 0);
|
||||
dispatch_source_set_event_handler(_timer, ^{
|
||||
|
||||
// 倒计时结束,关闭
|
||||
if (timeOut <= 0) {
|
||||
dispatch_source_cancel(_timer);
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
|
||||
self.backgroundColor = mColor;
|
||||
[self setTitle:title forState:UIControlStateNormal];
|
||||
self.userInteractionEnabled = YES;
|
||||
|
||||
});
|
||||
|
||||
}else{
|
||||
|
||||
int seconds = timeOut % 60;
|
||||
NSString * timeStr = [NSString stringWithFormat:@"%0.2d",seconds];
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
self.backgroundColor = color;
|
||||
[self setTitle:[NSString stringWithFormat:@"%@%@",timeStr,subTitle] forState:UIControlStateNormal];
|
||||
self.userInteractionEnabled = NO;
|
||||
});
|
||||
|
||||
timeOut--;
|
||||
}
|
||||
});
|
||||
|
||||
dispatch_resume(_timer);
|
||||
}
|
||||
@end
|
||||
@@ -0,0 +1,73 @@
|
||||
//
|
||||
// UIView+DESIGNABLE.h
|
||||
// BESIGNABLE
|
||||
//
|
||||
// Created by 123 on 16/5/22.
|
||||
// Copyright © 2016年 asura. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
typedef NS_OPTIONS(NSInteger, BBTSide) {
|
||||
BBTSideTopLeft = 1 << 0,
|
||||
BBTSideTopRight = 1 << 1,
|
||||
BBTSideBottomLeft = 1 << 2,
|
||||
BBTSideBottomRight = 1 << 3,
|
||||
BBTSideAll = 0xffff
|
||||
};
|
||||
|
||||
IB_DESIGNABLE
|
||||
|
||||
@interface UIView (EXTENSION)
|
||||
|
||||
//IB
|
||||
@property (nonatomic, assign) IB_DESIGNABLE CGFloat cornerRadius;
|
||||
@property (nonatomic, assign) IBInspectable CGFloat borderWidth;
|
||||
@property (nonatomic, assign) IBInspectable CGFloat defineValue;
|
||||
@property (nonatomic, assign) IBInspectable UIColor *borderColor;
|
||||
|
||||
/** 坐标 **/
|
||||
//originX
|
||||
@property (nonatomic) CGFloat originX;
|
||||
|
||||
//originY
|
||||
@property (nonatomic) CGFloat originY;
|
||||
|
||||
//originX + width
|
||||
@property (nonatomic) CGFloat rightX;
|
||||
|
||||
//originY + height
|
||||
@property (nonatomic) CGFloat bottomY;
|
||||
|
||||
//originY
|
||||
@property (nonatomic) CGFloat width;
|
||||
|
||||
//height
|
||||
@property (nonatomic) CGFloat height;
|
||||
|
||||
//centerX
|
||||
@property (nonatomic) CGFloat centerX;
|
||||
|
||||
//centerY
|
||||
@property (nonatomic) CGFloat centerY;
|
||||
|
||||
//origin
|
||||
@property (nonatomic) CGPoint origin;
|
||||
|
||||
//size
|
||||
@property (nonatomic) CGSize size;
|
||||
|
||||
// 移除此view上的所有子视图
|
||||
- (void)removeAllSubviews;
|
||||
|
||||
//获取视图所在的 UIViewController
|
||||
- (UIViewController *)viewController;
|
||||
/**
|
||||
* 切圆角
|
||||
*
|
||||
* @param side 圆角的位置
|
||||
* @param spacing 切得大小
|
||||
*/
|
||||
- (void)roundWithSide:(BBTSide)side spacing:(CGFloat)spacing;
|
||||
|
||||
@end
|
||||
+284
@@ -0,0 +1,284 @@
|
||||
//
|
||||
// UIView+DESIGNABLE.m
|
||||
// BESIGNABLE
|
||||
//
|
||||
// Created by 123 on 16/5/22.
|
||||
// Copyright © 2016年 asura. All rights reserved.
|
||||
//
|
||||
|
||||
#import "UIView+EXTENSION.h"
|
||||
#import <objc/runtime.h>
|
||||
|
||||
@implementation UIView (EXTENSION)
|
||||
|
||||
#pragma mark - IB
|
||||
- (void)setCornerRadius:(CGFloat)cornerRadius{
|
||||
self.layer.masksToBounds = YES;
|
||||
self.layer.cornerRadius = cornerRadius;
|
||||
}
|
||||
|
||||
- (void)setBorderColor:(UIColor *)borderColor{
|
||||
self.layer.borderColor = borderColor.CGColor;
|
||||
}
|
||||
|
||||
- (void)setBorderWidth:(CGFloat)borderWidth{
|
||||
self.layer.borderWidth = borderWidth;
|
||||
}
|
||||
|
||||
- (void)setDefineValue:(CGFloat)defineValue{
|
||||
objc_setAssociatedObject(self, @selector(defineValue), @(defineValue), OBJC_ASSOCIATION_ASSIGN);
|
||||
}
|
||||
|
||||
- (CGFloat)cornerRadius{
|
||||
return self.layer.cornerRadius;
|
||||
}
|
||||
|
||||
- (UIColor *)borderColor{
|
||||
return [UIColor colorWithCGColor:self.layer.borderColor];
|
||||
}
|
||||
|
||||
- (CGFloat)borderWidth{
|
||||
return self.layer.borderWidth;
|
||||
}
|
||||
|
||||
- (CGFloat)defineValue{
|
||||
return [objc_getAssociatedObject(self, @selector(defineValue)) floatValue];
|
||||
}
|
||||
|
||||
#pragma mark - 坐标
|
||||
- (void)setOriginX:(CGFloat)originX {
|
||||
CGRect frame = self.frame;
|
||||
frame.origin.x = originX;
|
||||
self.frame = frame;
|
||||
return;
|
||||
}
|
||||
|
||||
- (CGFloat)originX {
|
||||
return self.frame.origin.x;
|
||||
}
|
||||
|
||||
- (void)setOriginY:(CGFloat)originY {
|
||||
CGRect frame = self.frame;
|
||||
frame.origin.y = originY;
|
||||
self.frame = frame;
|
||||
return;
|
||||
}
|
||||
|
||||
- (CGFloat)originY {
|
||||
return self.frame.origin.y;
|
||||
}
|
||||
|
||||
- (void)setRightX:(CGFloat)rightX {
|
||||
CGRect frame = self.frame;
|
||||
frame.origin.x = rightX - [self width];
|
||||
self.frame = frame;
|
||||
return;
|
||||
}
|
||||
|
||||
- (CGFloat)rightX {
|
||||
return [self originX] + [self width];
|
||||
}
|
||||
|
||||
- (void)setBottomY:(CGFloat)bottomY {
|
||||
CGRect frame = self.frame;
|
||||
frame.origin.y = bottomY - [self height];
|
||||
self.frame = frame;
|
||||
return;
|
||||
}
|
||||
|
||||
- (CGFloat)bottomY {
|
||||
return [self originY] + [self height];
|
||||
}
|
||||
|
||||
- (void)setCenterX:(CGFloat)centerX {
|
||||
self.center = CGPointMake(centerX, self.center.y);
|
||||
return;
|
||||
}
|
||||
|
||||
- (CGFloat)centerX {
|
||||
return self.center.x;
|
||||
}
|
||||
|
||||
- (void)setCenterY:(CGFloat)centerY {
|
||||
self.center = CGPointMake(self.center.x, centerY);
|
||||
return;
|
||||
}
|
||||
|
||||
- (CGFloat)centerY {
|
||||
return self.center.y;
|
||||
}
|
||||
|
||||
- (void)setWidth:(CGFloat)width {
|
||||
CGRect frame = self.frame;
|
||||
frame.size.width = width;
|
||||
self.frame = frame;
|
||||
return;
|
||||
}
|
||||
|
||||
- (CGFloat)width {
|
||||
return self.frame.size.width;
|
||||
}
|
||||
|
||||
- (void)setHeight:(CGFloat)height {
|
||||
CGRect frame = self.frame;
|
||||
frame.size.height = height;
|
||||
self.frame = frame;
|
||||
return;
|
||||
}
|
||||
|
||||
- (CGFloat)height {
|
||||
return self.frame.size.height;
|
||||
}
|
||||
|
||||
- (void)setOrigin:(CGPoint)origin {
|
||||
CGRect frame = self.frame;
|
||||
frame.origin = origin;
|
||||
self.frame = frame;
|
||||
return;
|
||||
}
|
||||
|
||||
- (CGPoint)origin {
|
||||
return self.frame.origin;
|
||||
}
|
||||
|
||||
- (void)setSize:(CGSize)size {
|
||||
CGRect frame = self.frame;
|
||||
frame.size = size;
|
||||
self.frame = frame;
|
||||
return;
|
||||
}
|
||||
|
||||
- (CGSize)size {
|
||||
return self.frame.size;
|
||||
}
|
||||
|
||||
|
||||
// 移除此view上的所有子视图
|
||||
- (void)removeAllSubviews {
|
||||
for (UIView *view in self.subviews) {
|
||||
[view removeFromSuperview];
|
||||
}
|
||||
}
|
||||
//获取视图所在的 UIViewController
|
||||
- (UIViewController *)viewController
|
||||
{
|
||||
for (UIView *next = [self superview]; next; next = next.superview) {
|
||||
UIResponder *nextResponder = [next nextResponder];
|
||||
if ([nextResponder isKindOfClass:[UIViewController class]]) {
|
||||
return (UIViewController *)nextResponder;
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
//切圆角
|
||||
- (void)roundWithSide:(BBTSide)side spacing:(CGFloat)spacing
|
||||
{
|
||||
UIBezierPath *maskPath;
|
||||
switch (side) {
|
||||
case BBTSideTopLeft: {
|
||||
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
|
||||
byRoundingCorners:UIRectCornerTopLeft
|
||||
cornerRadii:CGSizeMake(spacing, spacing)];
|
||||
break;
|
||||
}
|
||||
case BBTSideTopRight: {
|
||||
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
|
||||
byRoundingCorners:UIRectCornerTopRight
|
||||
cornerRadii:CGSizeMake(spacing, spacing)];
|
||||
break;
|
||||
}
|
||||
case BBTSideBottomLeft: {
|
||||
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
|
||||
byRoundingCorners:UIRectCornerBottomLeft
|
||||
cornerRadii:CGSizeMake(spacing, spacing)];
|
||||
break;
|
||||
}
|
||||
case BBTSideBottomRight: {
|
||||
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
|
||||
byRoundingCorners:UIRectCornerBottomRight
|
||||
cornerRadii:CGSizeMake(spacing, spacing)];
|
||||
break;
|
||||
}
|
||||
case BBTSideAll: {
|
||||
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
|
||||
byRoundingCorners:UIRectCornerAllCorners
|
||||
cornerRadii:CGSizeMake(spacing, spacing)];
|
||||
break;
|
||||
}
|
||||
}
|
||||
//上左,下左
|
||||
if (side == (BBTSideTopLeft | BBTSideBottomLeft)) {
|
||||
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
|
||||
byRoundingCorners:UIRectCornerTopLeft | UIRectCornerBottomLeft
|
||||
cornerRadii:CGSizeMake(spacing, spacing)];
|
||||
}
|
||||
//上左,下右
|
||||
if (side == (BBTSideTopLeft | BBTSideBottomRight)) {
|
||||
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
|
||||
byRoundingCorners:UIRectCornerTopLeft | UIRectCornerBottomRight
|
||||
cornerRadii:CGSizeMake(spacing, spacing)];
|
||||
}
|
||||
//上右,下左
|
||||
if (side == (BBTSideTopLeft | BBTSideBottomRight)) {
|
||||
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
|
||||
byRoundingCorners:UIRectCornerTopLeft | UIRectCornerBottomRight
|
||||
cornerRadii:CGSizeMake(spacing, spacing)];
|
||||
}
|
||||
//上右,下右
|
||||
if (side == (BBTSideTopRight | BBTSideBottomRight)) {
|
||||
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
|
||||
byRoundingCorners:UIRectCornerTopRight | UIRectCornerBottomRight
|
||||
cornerRadii:CGSizeMake(spacing, spacing)];
|
||||
}
|
||||
//上右,上左
|
||||
if (side == (BBTSideTopRight | BBTSideTopLeft)) {
|
||||
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
|
||||
byRoundingCorners:UIRectCornerTopRight | UIRectCornerTopLeft
|
||||
cornerRadii:CGSizeMake(spacing, spacing)];
|
||||
}
|
||||
//下左,下右
|
||||
if (side == (BBTSideBottomLeft | BBTSideBottomRight)) {
|
||||
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
|
||||
byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight
|
||||
cornerRadii:CGSizeMake(spacing, spacing)];
|
||||
}
|
||||
//上左,上右,下左
|
||||
if (side == (BBTSideTopLeft | BBTSideBottomLeft | BBTSideTopRight)) {
|
||||
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
|
||||
byRoundingCorners:UIRectCornerTopLeft | UIRectCornerBottomRight | UIRectCornerTopRight
|
||||
cornerRadii:CGSizeMake(spacing, spacing)];
|
||||
}
|
||||
//上左,上右,下右
|
||||
if (side == (BBTSideTopLeft | BBTSideBottomRight | BBTSideTopRight)) {
|
||||
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
|
||||
byRoundingCorners:UIRectCornerTopLeft | UIRectCornerBottomRight | UIRectCornerTopRight
|
||||
cornerRadii:CGSizeMake(spacing, spacing)];
|
||||
}
|
||||
//上右,下左,下右
|
||||
if (side == (BBTSideTopRight | BBTSideBottomLeft | BBTSideBottomRight)) {
|
||||
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
|
||||
byRoundingCorners:UIRectCornerTopRight | UIRectCornerBottomRight | UIRectCornerBottomLeft
|
||||
cornerRadii:CGSizeMake(spacing, spacing)];
|
||||
}
|
||||
//上左,下左,下右
|
||||
if (side == (BBTSideTopLeft | BBTSideBottomLeft | BBTSideBottomRight)) {
|
||||
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
|
||||
byRoundingCorners:UIRectCornerTopLeft | UIRectCornerBottomRight | UIRectCornerBottomLeft
|
||||
cornerRadii:CGSizeMake(spacing, spacing)];
|
||||
}
|
||||
if (side == (BBTSideTopLeft | BBTSideBottomLeft | BBTSideBottomRight | BBTSideTopRight)) {
|
||||
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
|
||||
byRoundingCorners:UIRectCornerAllCorners
|
||||
cornerRadii:CGSizeMake(spacing, spacing)];
|
||||
}
|
||||
// Create the shape layer and set its path
|
||||
CAShapeLayer *maskLayer = [CAShapeLayer layer];
|
||||
maskLayer.frame = self.bounds;
|
||||
maskLayer.path = maskPath.CGPath;
|
||||
|
||||
// Set the newly created shape layer as the mask for the image view's layer
|
||||
self.layer.mask = maskLayer;
|
||||
|
||||
self.layer.masksToBounds = YES;
|
||||
}
|
||||
@end
|
||||
Reference in New Issue
Block a user