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 ...
随机推荐
- django后台显示图片 而不是图片地址
修改admin代码 class Ad_CampaingAdmin(admin.ModelAdmin): list_display = ("content","previe ...
- Pandas Dataframe增、删、改、查、去重、抽样基本操作
总括 pandas的索引函数主要有三种: loc 标签索引,行和列的名称 iloc 整型索引(绝对位置索引),绝对意义上的几行几列,起始索引为0 ix 是 iloc 和 loc的合体 at是loc的快 ...
- ARKit从入门到精通(6)-ARSession介绍
转载:http://blog.csdn.net/u013263917/article/details/73157082 ARSession是一个连接底层与AR视图之间的桥梁,其实ARSCNView内部 ...
- 微服务之springCloud-config-bus(十三)
简介 当我们的业务系统越来越庞大复杂的时候,各种配置就会层出不群.一旦配置修改了,那么我们就是必须修改后停服务,然后再上线,如果服务少,我们可以手动来操作,如果是成千上百的服务,如果是手动操作,肯定就 ...
- kafka 面试题 无答案
kafka节点之间如何复制备份的? kafka消息是否会丢失?为什么? kafka最合理的配置是什么? kafka的leader选举机制是什么? kafka对硬件的配置有什么要求? kafka的消息保 ...
- android sqlite应用优化(资料整理)
1. 优化插入速度 a.不要绑定空列 在我的程序,至少有50%的列是空值.碰到空值列,就不调用ih.bind()方法对它进行绑定,就我的程序而言,当列值为null或者空的字符串是, 有将近30 ...
- C语言 · 生物芯片
标题:生物芯片 X博士正在研究一种生物芯片.博士在芯片中设计了 n 个微型光源,每个光源操作一次就会改变其状态,即:点亮转为关闭,或关闭转为点亮. 这些光源的编号从 1 到 n,开始的时候所有光源都是 ...
- C语言 · 新生舞会
算法训练 新生舞会 时间限制:1.0s 内存限制:512.0MB 问题描述 新生舞会开始了.n名新生每人有三个属性:姓名.学号.性别.其中,姓名用长度不超过20的仅由大小写字母构成的 ...
- Kafka内核中的分布式机制实现
Kafka内核中的分布式机制实现 一个Topic中的所有数据分布式的存储在kafka集群的所有机器(broker)上,以分区(partition)的的形式进行数据存储:每个分区允许存在备份数据/备份分 ...
- 使用postman测试文件上传
调试API神奇----postman 请求方法:POST Body-->form-data-->key(选择file) QQ技术交流群:282575808 ---------------- ...