zoukankan      html  css  js  c++  java
  • 一个实用的UIView的类别

    //
    //  FrameAccessor.h
    //  FrameAccessor
    //
    //  Created by Alex Denisov on 18.03.12.
    //  Copyright (c) 2013 okolodev.org. All rights reserved.
    //
    
    #if (TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE)
       #import <UIKit/UIKit.h>
       #define View UIView
    #else
       #import <Foundation/Foundation.h>
       #define View NSView
    #endif
    
    @interface UIView (FrameAccessor)
    
    - (CGPoint)origin;
    - (void)setOrigin:(CGPoint)newOrigin;
    - (CGSize)size;
    - (void)setSize:(CGSize)newSize;
    
    - (CGFloat)x;
    - (void)setX:(CGFloat)newX;
    - (CGFloat)y;
    - (void)setY:(CGFloat)newY;
    
    - (CGFloat)height;
    - (void)setHeight:(CGFloat)newHeight;
    - (CGFloat)width;
    - (void)setWidth:(CGFloat)newWidth;
    
    - (CGFloat)bottom;
    - (CGFloat)right;
    
    @end
    //  FrameAccessor.m
    //  FrameAccessor
    //
    //  Created by Alex Denisov on 18.03.12.
    //  Copyright (c) 2013 okolodev.org. All rights reserved.
    //
    
    #import "FrameAccessor.h"
    
    @implementation UIView (FrameAccessor)
    
    - (CGPoint)origin {
       return self.frame.origin;
    }
    
    - (void)setOrigin:(CGPoint)newOrigin {
       CGRect newFrame = self.frame;
       newFrame.origin = newOrigin;
       self.frame = newFrame;
    }
    
    - (CGSize)size {
       return self.frame.size;
    }
    
    - (void)setSize:(CGSize)newSize {
       CGRect newFrame = self.frame;
       newFrame.size = newSize;
       self.frame = newFrame;
    }
    
    - (CGFloat)x {
       return self.frame.origin.x;
    }
    
    - (void)setX:(CGFloat)newX {
       CGRect newFrame = self.frame;
       newFrame.origin.x = newX;
       self.frame = newFrame;
    }
    
    - (CGFloat)y {
       return self.frame.origin.y;
    }
    
    - (void)setY:(CGFloat)newY {
       CGRect newFrame = self.frame;
       newFrame.origin.y = newY;
       self.frame = newFrame;
    }
    
    - (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)bottom {
       return self.frame.origin.y + self.frame.size.height;
    }
    
    - (CGFloat)right {
       return self.frame.origin.x + self.frame.size.width;
    }
    
    @end
    终于明白,“喜欢”是一种莫大的能量!
  • 相关阅读:
    完美解决 向UILable 文字最后插入N张图片,支持向限制行数的UILable 最后一行插入,多余文字显示...
    构建自己的NSZombie
    如何以代码形式插入断点
    根据坐标点显示地图显示范围(高德地图)
    ios7 UITableView 分割线在 使用selectedBackgroundView 选中时有些不显示
    runtime MethodSwizzle 实践之 奇怪crash : [UIKeyboardLayoutStar release]: message sent to deallocated instance
    Jmeter(十一)
    Jmeter(十)
    Jmeter(九)
    Jmeter(八)
  • 原文地址:https://www.cnblogs.com/tml839720759/p/3196954.html
Copyright © 2011-2022 走看看