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 ...
随机推荐
- js实现冒泡事件,点击ul给子标签添加相同事件和阻止冒泡事件
$('#LocalLife_PopUp_layer').find('.SelectCity_Cont ul').click(function(e){ var e=e||windo ...
- JAVA-JSP内置对象之out对象进行页面输出
相关资料:<21天学通Java Web开发> out对象 out对象进行页面输出1.通过out对象的print()方法和println()方法进行页而输出.2.不同的println()方法 ...
- C#学习笔记(28)——委托排序(2)自定义排序
说明(2017-11-21 15:24:50): 1. 定义一个排序方法,参数是字符串数组,和委托.MySort(nums, string.Compare),调用时只需要更换里面的委托方法就行,或者直 ...
- 6. 支持向量机(SVM)核函数
1. 感知机原理(Perceptron) 2. 感知机(Perceptron)基本形式和对偶形式实现 3. 支持向量机(SVM)拉格朗日对偶性(KKT) 4. 支持向量机(SVM)原理 5. 支持向量 ...
- Android Retrofit2 数据解析
在弄数据解析这块,浪费了很长的时间,最开始一直觉得传过来用对象接收的,类型是json,往那个方式去想了.搞了很久. 后来看了别人写的才发觉,真是很简单,感谢 https://www.jianshu.c ...
- [转]oracle制定定时任务(dbms_jobs)
原文地址:http://www.cnblogs.com/siashan/p/4183868.html 本节摘要:本节介绍使用oracle自带的job来实现oracle定制定时执行任务. 1.引言 ...
- wamp升级php5.3.10到php5.6.13版本
1. 停止WAMP服务器. 2. 去网站windows.php.net 下载php-5.6.13-nts-Win32-VC9-x86.zip. 不要下载THE INSTALLER. 3. 在wa ...
- [ADC]TI am4378 ADC采样设置问题(am335x类似)
这段时间在调试AM4378的ADC问题,发现采样到的数据和真实输入波形有所出入,比如输入是1ms的周期,50%占空比的信号,但是采样的数据描点总是偏差较大,数据如下 iio device number ...
- Java编程的逻辑 (50) - 剖析EnumMap
本系列文章经补充和完善,已修订整理成书<Java编程的逻辑>,由机械工业出版社华章分社出版,于2018年1月上市热销,读者好评如潮!各大网店和书店有售,欢迎购买,京东自营链接:http:/ ...
- 【转载】解决Windows和Ubuntu时间不一致的问题
大家在切换操作系统的时候会发现一个问题, Windows 和Ubuntu的时间会出现不一致的情况.在 Windows 中把时间设置正确了过后,回到在 Ubuntu 后系统的时间又不一样了,在 Ubun ...