iOS: 控制UIView的外形
#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(, length)];
[bezierPath addLineToPoint:CGPointMake(length, )];
[bezierPath addLineToPoint:CGPointMake(rect.size.width - length, )];
[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(, rect.size.height - length)];
[bezierPath closePath];
return bezierPath;
} @end
在[UIView viewWillAppear:]方法中加入下面代码
[self.view setShape:[UIBezierPath cutCorner:self.view.bounds length:].CGPath];
效果:

################
让自定义 Button 响应自定义 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;
}
//判断触发点是否在规定的 Shape 内
if (CGPathContainsPoint(path, nil, point, nil)) {
return YES;
}
return NO;
}
@end
iOS: 控制UIView的外形的更多相关文章
- iOS 控制单个控制器旋转
iOS 控制单个控制器旋转 控制单个ViewController 的旋转 //不旋转,保持竖屏 //iOS 5 - (BOOL) shouldAutorotateToInterfaceOrientat ...
- 荼菜的iOS笔记--UIView的几个Block动画
前言:我的第一篇文章荼菜的iOS笔记–Core Animation 核心动画算是比较详细讲了核心动画的用法,但是如你上篇看到的,有时我们只是想实现一些很小的动画,这时再用coreAnimation就会 ...
- ios 关于UIView 的multipleTouchEnabled 和 exclusiveTouch
做项目时发现,在一个界面上的2个button竟然可以同时点击,依次push进去了2个 controller!我就产生了疑问,一个view的multipleTouchEnabled属性默认是false啊 ...
- iOS学习——UIView的研究
在iOS开发中,我们知道有一个共同的基类——NSObject,但是对于界面视图而言,UIView是非常重要的一个类,UIView是很多视图控件的基类,因此,对于UIView的学习闲的非常有必要.在iO ...
- iOS开发UIView.h简介
1.UICoordinateSpace不同坐标空间的坐标切换 @protocol UICoordinateSpace <NSObject> //将当前的坐标空间点转换到指定的坐标空间 - ...
- iOS 使用UIView的一种有效方法
在一个典型的MVC结构 中,Model部分负责保存目标数据,View部分主要负责实现数据的界面以及将数据显示出来,二者在Controller的操作下协同工作.在iOS应用中,View的实现主要由UIV ...
- iOS之UIview动画
一.UIView动画(首尾) 1.简单说明 UIKit直接将动画集成到UIView类中,当内部的一些属性发生改变时,UIView将为这些改变提供动画支持 执行动画所需要的工作由UIView类自动完成, ...
- IOS自定义UIView
IOS中一般会用到几种方式自定义UIView 1.继承之UIView的存代码的自定义View 2.使用xib和代码一起使用的自定义View 3.存xib的自定义View(不需要业务处理的那种) 本文主 ...
- OpenGL ES: iOS 自定义 UIView 响应屏幕旋转
iOS下使用OpenGL 如果使用GLKit View 那么不用担心屏幕旋转的问题,说明如下: If you change the size, scale factor, or drawable pr ...
随机推荐
- jQuery 学习笔记1 弹出一个对话框
这里推荐使用sublime text 2来写,外加zen coding. 首先是写html 只需要html:xt,然后tab就可以得到一个html的完整结构. <!DOCTYPE html PU ...
- pandas的学习总结
pandas的学习总结 作者:csj更新时间:2017.12.31 email:59888745@qq.com 说明:因内容较多,会不断更新 xxx学习总结: 回主目录:2017 年学习记录和总结 1 ...
- 迷你版mvc框架执行过程
一.把路由添加到路由表, 二.注册ControllerBuilder(老板)和默认工厂(DefaultControllerFactory) 2.1默认工厂获取可以创建的Controller. 三.由于 ...
- layer关闭弹出层,弹出打印
常规的话,下面能够完成关闭弹出层 var index = parent.layer.getFrameIndex(window.name); //延迟关闭 解决打印窗口弹不出来的情况 parent.la ...
- Oracle 执行报错表空间或临时表空间不足,降低水位线方法
Oracle 执行语句插入临时表报表空间不足,在增加表空间到最大后依然报错,经分析应该为创建的临时表水位线未清除导致,查询降低水位线方法如下: 原文地址:http://blog.itpub.net/2 ...
- [转]使用DW正则表达式批量替换实例介绍
原文地址:http://www.jb51.net/Dreamweaver/86329.html 网站优化过程中,经常会遇到很多要批量修改的东西,一个个修改,明显效率低下.本文是使用DW正则表达式批量替 ...
- MEMCACHE分布式算法(PHP)
//测试分布式算法 $ports = array('端口1', '端口2', '端口3', '端口4', '端口5'); //Memcache端口 $users = array('1000', '10 ...
- JQUERY双下拉框内容的左右移动
教程源码:http://bbs.php100.com/read-htm-tid-74060.html用到的方法为:appendTo() 格式:$(content).appendTo(selector ...
- MAC OSX 10.10 下启用自带的Apache的rewrite模块
1.修改Apache配置文件 sudo vim /etc/apache2/httpd.conf LoadModule rewrite_module libexec/apache2/mod_rewrit ...
- [note]What I’ve learnt from working on startups
What I've learnt from working on startups 从失败里学到了什么,六次创业失败. 企业家不是与生俱来的,也是靠学来的. 想的太多,做的太少.