它们的定义View
Ios“巷自己的定义View和Android类别似
在.h文件设置了他的一些财产。方法
在.m文件中实现
.h文件
#import <UIKit/UIKit.h>
CGPoint CGRectGetCenter(CGRect rect);
CGRect CGRectMoveToCenter(CGRect rect,
CGPoint center);
@interface UIView (ViewFrameGeometry)
@property
CGPoint origin;
@property CGSize size;
@property (readonly)
CGPoint bottomLeft;
@property (readonly)
CGPoint bottomRight;
@property (readonly)
CGPoint topRight;
@property
CGFloat height;
@property CGFloat width;
@property CGFloat top;
@property CGFloat left;
@property
CGFloat bottom;
@property CGFloat right;
- (void) moveBy: (CGPoint) delta;
- (void) scaleBy: (CGFloat) scaleFactor;
- (void) fitInSize: (CGSize) aSize;
@end
.m文件
#import "UIViewExt.h"
CGPoint CGRectGetCenter(CGRect rect)
{
CGPoint pt;
pt.x =
CGRectGetMidX(rect);
pt.y =
CGRectGetMidY(rect);
return pt;
}
CGRect CGRectMoveToCenter(CGRect rect,
CGPoint center)
{
CGRect newrect = CGRectZero;
newrect.origin.x = center.x-CGRectGetMidX(rect);
newrect.origin.y = center.y-CGRectGetMidY(rect);
newrect.size = rect.size;
return newrect;
}
@implementation UIView (ViewGeometry)
// Retrieve and set the origin
- (CGPoint) origin
{
return
self.frame.origin;
}
- (void) setOrigin: (CGPoint) aPoint
{
CGRect newframe =
self.frame;
newframe.origin = aPoint;
self.frame = newframe;
}
// Retrieve and set the size
- (CGSize) size
{
return
self.frame.size;
}
- (void) setSize: (CGSize) aSize
{
CGRect newframe =
self.frame;
newframe.size = aSize;
self.frame = newframe;
}
// Query other frame locations
- (CGPoint) bottomRight
{
CGFloat x =
self.frame.origin.x +
self.frame.size.width;
CGFloat y =
self.frame.origin.y +
self.frame.size.height;
return
CGPointMake(x, y);
}
- (CGPoint) bottomLeft
{
CGFloat x =
self.frame.origin.x;
CGFloat y =
self.frame.origin.y +
self.frame.size.height;
return
CGPointMake(x, y);
}
- (CGPoint) topRight
{
CGFloat x =
self.frame.origin.x +
self.frame.size.width;
CGFloat y =
self.frame.origin.y;
return
CGPointMake(x, y);
}
// Retrieve and set height, width, top, bottom, left, right
- (CGFloat) height
{
return
self.frame.size.height;
}
- (void) setHeight: (CGFloat) newheight
{
CGRect newframe =
self.frame;
newframe.size.height = newheight;
self.frame = newframe;
}
- (CGFloat) width
{
return
self.frame.size.width;
}
- (void) setWidth: (CGFloat) newwidth
{
CGRect newframe =
self.frame;
newframe.size.width = newwidth;
self.frame = newframe;
}
- (CGFloat) top
{
return
self.frame.origin.y;
}
- (void) setTop: (CGFloat) newtop
{
CGRect newframe =
self.frame;
newframe.origin.y = newtop;
self.frame = newframe;
}
- (CGFloat) left
{
return
self.frame.origin.x;
}
- (void) setLeft: (CGFloat) newleft
{
CGRect newframe =
self.frame;
newframe.origin.x = newleft;
self.frame = newframe;
}
- (CGFloat) bottom
{
return
self.frame.origin.y +
self.frame.size.height;
}
- (void) setBottom: (CGFloat) newbottom
{
CGRect newframe =
self.frame;
newframe.origin.y = newbottom -
self.frame.size.height;
self.frame = newframe;
}
- (CGFloat) right
{
return
self.frame.origin.x +
self.frame.size.width;
}
- (void) setRight: (CGFloat) newright
{
CGFloat delta = newright - (self.frame.origin.x +
self.frame.size.width);
CGRect newframe =
self.frame;
newframe.origin.x += delta ;
self.frame = newframe;
}
// Move via offset
- (void) moveBy: (CGPoint) delta
{
CGPoint newcenter =
self.center;
newcenter.x += delta.x;
newcenter.y += delta.y;
self.center = newcenter;
}
// Scaling
- (void) scaleBy: (CGFloat) scaleFactor
{
CGRect newframe =
self.frame;
newframe.size.width *= scaleFactor;
newframe.size.height *= scaleFactor;
self.frame = newframe;
}
// Ensure that both dimensions fit within the given size by scaling down
- (void) fitInSize: (CGSize) aSize
{
CGFloat scale;
CGRect newframe =
self.frame;
if (newframe.size.height && (newframe.size.height > aSize.height))
{
scale = aSize.height / newframe.size.height;
newframe.size.width *= scale;
newframe.size.height *= scale;
}
if (newframe.size.width && (newframe.size.width >= aSize.width))
{
scale = aSize.width / newframe.size.width;
newframe.size.width *= scale;
newframe.size.height *= scale;
}
self.frame = newframe;
}
@end
版权声明:本文博客原创文章。博客,未经同意,不得转载。
它们的定义View的更多相关文章
- Android 它们的定义View (一)
转载请注明出处:http://blog.csdn.net/lmj623565791/article/details/24252901 非常Android入门程序员AndroidView.可能都是比較恐 ...
- Android 它们的定义View它BounceProgressBar
转载请注明出处:http://blog.csdn.net/bbld_/article/details/41246247 [Rocko's blog] 之前几天下载了非常久没用了的桌面版酷狗来用用的时候 ...
- Android 自己定义View (二) 进阶
转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/24300125 继续自己定义View之旅.前面已经介绍过一个自己定义View的基础 ...
- 【android自己定义控件】自己定义View属性
1.自己定义View的属性 2.在View的构造方法中获得我们自己定义的属性 3.重写onMesure 4.重写onDraw 3这个步骤不是必须,当然了大部分情况下还是须要重写的. 1.自己定义Vie ...
- Qt--自定义View
这是上一篇文章的续篇,关于自定义View. 多个View内部可以映射到同一个数据模型,也可以映射不同的数据结构:可以使用所有数据,也可以只使用部分数据.因为视图层与数据层的分离,操作相对比较灵活. 1 ...
- 自己定义View Controller转换动画
原文链接 : Introduction to Custom View Controller Transitions and Animations 原文作者 : joyce echessa 译文出自 : ...
- Android-自定义View前传-View的三大流程-Layout
Android-自定义View前传-View的三大流程-Layout 参考 <Android开发艺术探索> https://github.com/hongyangAndroid/FlowL ...
- 图文剖析自己定义View的绘制(以自己定义滑动button为例)
自己定义View一直是横在Android开发人员面前的一道坎. 一.View和ViewGroup的关系 从View和ViewGroup的关系来看.ViewGroup继承View. View的子类.多是 ...
- 自己定义View Layout过程 - 最易懂的自己定义View原理系列(3)
前言 自己定义View是Android开发人员必须了解的基础 网上有大量关于自己定义View原理的文章.但存在一些问题:内容不全.思路不清晰.无源代码分析.简单问题复杂化等等 今天,我将全面总结自己定 ...
随机推荐
- VS2008非托管C++调用wcf(WebService)服务
在Visual Studio 2008以及以后版本中,微软停止了非托管C++的直接WebService引用.不过ATL Server代码已经托管到开源网站上,我们可以找到ATL Server的源代码, ...
- Python学习之路——socket
一.Socket通常也称作"套接字",用于描述IP地址和端口,是一个通信链的句柄,可以用来实现不同虚拟机或不同计算机之间的通信. socket服务端示例: import socke ...
- C语言循环小技巧
写代码,有两类追求,一种是追求实用(Coder),一种是追求代码艺术(Artist) 我是那种追实用追腻了,偶然追一下艺术(就是偶然和艺术有一腿)的那种Coder 很多人,已经习惯了for(i=0; ...
- linq 总结
linq 常用方法: top var query=(from u in User ...).Take(10) dblinq的坑: 时间必须当参数传入,否则会报错 多个left join时,如果jo ...
- linux基础随笔
磁盘管理 sda s:磁盘接口的类型(sata scsci sas) d:驱动器(drive) a:(第一块磁盘,同理b第二块磁盘)hda h:ide接口 第一块磁盘的第一个分区:sda1 mount ...
- GridView用法的修改和删除
(前台) <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="Fa ...
- 禁用 Windows Azure 网站中的 ARR 实例关联
编辑人员注释: 本博客文章由 Windows Azure 网站团队的项目经理 Erez Benari 撰写. 在 Windows Azure 网站中设置网站的多个实例是横向扩展网站的绝佳方式,Azur ...
- IT第四天 - 运算符、随机数、Math类
IT第四天 上午 运算符 1.%运算符的应用 2.运算符优先级:小括号 ! 算数运算符 关系运算符 && || 赋值运算符 3.三元运算符:?表示条件为true的结果,:表示条件为 ...
- libpng causes error concerning pngconf.h
Bug Description Ubuntu Gutsy Gibbon 7.10 - libpng 1.2.15~beta5-2ubuntu0.1 (bug probably concerned wi ...
- iOS之UITableViewCell左右滑动效果
首先在 UITableViewCell.h 中声明一个代理 @protocol UITableViewCellSlideDelegate <UITableViewDelegate> @op ...