#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
@interface uiview (Shape)
-(void ) Setshape: (cgpathref) shape;
@end
#import "Uiview+shape.h"
@implementation UIView (Shape)
-(void) Setshape: (cgpathref) Shape
{
if ( Shape = = nil) {
self.layer.mask = nil;
}
cashapelayer* Masklayer = [Cashapelayer layer];
Masklayer.path = shape;
Self.layer.mask = Masklayer;
}
@end
@interface Uibezierpath (Basicshape)
+ (Uibezierpath *) Cutcorner: (cgrect) originalframe length: (cgfloat) length;
@end
#import "Uibezierpath+basicshape.h"
@implementation Uibezierpath (basicshape)
+ (Uibezierpath *) Cutcorner: ( CGRect) originalframe Length: (cgfloat) length
{
CGRect rect = originalframe;
Uibezierpath *bezierpath = [Uibezierpath Bezierpath];
[Bezierpath movetopoint:cgpointmake (0, length)];
[Bezierpath addlinetopoint:cgpointmake (length, 0)];
[Bezierpath addlinetopoint:cgpointmake (rect.size.width-length, 0)];
[Bezierpath addlinetopoint:cgpointmake (rect.size.width, length)];
[Bezierpath Addlinetopoint:cgpointmake (Rect.size.width, Rect.size.height-length)];
[Bezierpath Addlinetopoint:cgpointmake (Rect.size.width-length, Rect.size.height)];
[Bezierpath addlinetopoint:cgpointmake (length, rect.size.height)];
[Bezierpath addlinetopoint:cgpointmake (0, Rect.size.height-length)];
[Bezierpath Closepath];
return bezierpath;
}
@end
How to: Add the following code in the [UIView viewwillappear:] Method
[Self.view Setshape:[uibezierpath cutCorner:self.view.bounds length:40]. Cgpath];
Effect:
Allow custom Button to respond to click events in Custom Shape
#import <UIKit/UIKit.h>
#import "uiview+shape.h"
#import "uibezierpath+basicshape.h"
@interface rfbutton:uibutton{
cgpathref path;
}
@end
//// rfbutton.m
//Christapp//// Created by haozhen Li on 13-12-6.
//
#import "RFButton.h"
@implementation Rfbutton
-(ID) initWithFrame: (CGRect) frame
{
self = [super Initwithframe:frame];
if (self) {
//initialization code
} return
self;
}
-(void) Setshape: (cgpathref) shape
{
[super Setshape:shape];
Path = shape;
}
-(BOOL) Pointinside: (cgpoint) point withevent: (Uievent *) event
{
if (cgpathisempty (path)) {return
YES ;
}
Determine if the trigger point is within the specified Shape
if (cgpathcontainspoint (path, nil, point, nil)) {return
YES
}
return NO;
}
@end