#import <UIKit/UIKit.h> @interface UIView (Additon) /** * Shortcut for frame.origin.x. * * Sets frame.origin.x = left */ @property (nonatomic) CGFloat left; /** * Shortcut for frame.origin.y * * Sets frame.origin.y = top */ @property (nonatomic) CGFloat top; /** * Shortcut for frame.origin.x + frame.size.width * * Sets frame.origin.x = right - frame.size.width */ @property (nonatomic) CGFloat right; /** * Shortcut for frame.origin.y + frame.size.height * * Sets frame.origin.y = bottom - frame.size.height */ @property (nonatomic) CGFloat bottom; /** * Shortcut for frame.size.width * * Sets frame.size.width = width */ @property (nonatomic) CGFloat width; /** * Shortcut for frame.size.height * * Sets frame.size.height = height */ @property (nonatomic) CGFloat height; /** * Shortcut for frame.origin */ @property (nonatomic) CGPoint origin; /** * Shortcut for frame.size */ @property (nonatomic) CGSize size; @property (nonatomic) CGFloat centerX; @property (nonatomic) CGFloat centerY; - (id)subviewWithTag:(NSInteger)tag; - (UIViewController*)viewController; @end
#import "UIView+Additon.h" @implementation UIView (Additon) /////////////////////////////////////////////////////////////////////////////////////////////////// - (CGFloat)left { return self.frame.origin.x; } /////////////////////////////////////////////////////////////////////////////////////////////////// - (void)setLeft:(CGFloat)x { CGRect frame = self.frame; frame.origin.x = x; self.frame = frame; } /////////////////////////////////////////////////////////////////////////////////////////////////// - (CGFloat)top { return self.frame.origin.y; } /////////////////////////////////////////////////////////////////////////////////////////////////// - (void)setTop:(CGFloat)y { CGRect frame = self.frame; frame.origin.y = y; self.frame = frame; } /////////////////////////////////////////////////////////////////////////////////////////////////// - (CGFloat)right { return self.left + self.width; } /////////////////////////////////////////////////////////////////////////////////////////////////// - (void)setRight:(CGFloat)right { if(right == self.right){ return; } CGRect frame = self.frame; frame.origin.x = right - frame.size.width; self.frame = frame; } /////////////////////////////////////////////////////////////////////////////////////////////////// - (CGFloat)bottom { return self.top + self.height; } /////////////////////////////////////////////////////////////////////////////////////////////////// - (void)setBottom:(CGFloat)bottom { if(bottom == self.bottom){ return; } CGRect frame = self.frame; frame.origin.y = bottom - frame.size.height; self.frame = frame; } /////////////////////////////////////////////////////////////////////////////////////////////////// - (CGFloat)centerX { return self.center.x; } /////////////////////////////////////////////////////////////////////////////////////////////////// - (void)setCenterX:(CGFloat)centerX { self.center = CGPointMake(centerX, self.center.y); } /////////////////////////////////////////////////////////////////////////////////////////////////// - (CGFloat)centerY { return self.center.y; } /////////////////////////////////////////////////////////////////////////////////////////////////// - (void)setCenterY:(CGFloat)centerY { self.center = CGPointMake(self.center.x, centerY); } /////////////////////////////////////////////////////////////////////////////////////////////////// - (CGFloat)width { return self.frame.size.width; } /////////////////////////////////////////////////////////////////////////////////////////////////// - (void)setWidth:(CGFloat)width { CGRect frame = self.frame; frame.size.width = width; self.frame = frame; } /////////////////////////////////////////////////////////////////////////////////////////////////// - (CGFloat)height { return self.frame.size.height; } /////////////////////////////////////////////////////////////////////////////////////////////////// - (void)setHeight:(CGFloat)height { if(height == self.height){ return; } CGRect frame = self.frame; frame.size.height = height; self.frame = frame; } /////////////////////////////////////////////////////////////////////////////////////////////////// - (CGPoint)origin { return self.frame.origin; } /////////////////////////////////////////////////////////////////////////////////////////////////// - (void)setOrigin:(CGPoint)origin { CGRect frame = self.frame; frame.origin = origin; self.frame = frame; } /////////////////////////////////////////////////////////////////////////////////////////////////// - (CGSize)size { return self.frame.size; } /////////////////////////////////////////////////////////////////////////////////////////////////// - (void)setSize:(CGSize)size { CGRect frame = self.frame; frame.size = size; self.frame = frame; } /////////////////////////////////////////////////////////////////////////////////////////////////// - (UIView*)descendantOrSelfWithClass:(Class)cls { if ([self isKindOfClass:cls]) return self; for (UIView* child in self.subviews) { UIView* it = [child descendantOrSelfWithClass:cls]; if (it) return it; } return nil; } - (id)subviewWithTag:(NSInteger)tag{ for(UIView *view in [self subviews]){ if(view.tag == tag){ return view; } } return nil; } - (UIViewController*)viewController { for (UIView* next = [self superview]; next; next = next.superview) { UIResponder* nextResponder = [next nextResponder]; if ([nextResponder isKindOfClass:[UIViewController class]]) { return (UIViewController*)nextResponder; } } return nil; } @end
相关推荐
UIView 动画 UIView动画
ios中关于uiview
UIView AutoLayout ,UIView AutoLayout 是 UIView 的分类,实现了自动布局限制的简单接口。 T...
详细讲解UIView的生命循环周期,对开发者有更好的启发作用,深层次了解程序运行的流程。
UIView-Positioning, 在UIView对象中,基于简单属性的框架属性设置 uiview定位收费 UIView Positioning 是一个快速扩展,它提供简单的shorthand 方法,以方便的方式定义任何UIView对象的框架属性( 宽度,高度,x,y ...
UIView+Extension 对view的一个扩展
1、将UIView 保存为图片,按照给定的scale 2、stackoverflow参照 3、保存的图片为依据scale,亲测
+ (UIView *_Nullable)az_gradientViewWithColors:(NSArray*> *_Nullable)colors locations:(NSArray*> *_Nullable)locations startPoint:(CGPoint)startPoint endPoint:(CGPoint)endPoint; - (void)az_...
已封装好的实现渐变的UIView,只需传入渐变开始值和结束值就可直接使用。有四种渐变方向可选
为UIView添加圆角扩展
简单的把UIView转化为UIImage,大家可以看下。
iOS中UIView的翻页动画demo 有几个是私有的api,小心使用。
iPhone开发学习笔记005——使用XIB自定义一个UIView,然后将这个view添加到controller的view。
通过协议扩展高斯模糊任意 UIView.zip,对任何具有swift协议扩展的uiview应用高斯模糊
uiview+frame,方便UI布局,码农工具,第一次上传,测下好用不
自定义UIView动画 http://blog.csdn.net/brycegao321/article/details/53817222
xamarin学习笔记B03(ios的UIView的了解)它是所有视图控件的父类。例如UIButton、UILabel、UIImageView等都最终是继承自UIView。它可以添加其它视图作为它的子视图。
好程序员学习笔记--UI基础UIWindow、UIView.doc
轻量级组件能够让所有 UIView 都支持进度条展示
UIView 震动动画效果 AFViewShaker ,AFViewShaker 是一个简单的工具用来执行 。 使用方法: AFViewShaker *...