第一天06-封装frame的修改

// UIView + LYExtension.h
// Created by YoungLee on **/**/**
// Copyright (c) **** YoungLee.All rights reserved.

#import <UIKit/UIKit.h>

@interface UIView(LYExtension)

// 在分类中声明@property,只会生成方法的声明,不会生成方法的实现。
@property(nonatomic, assign)CGSize size;
@property(nonatomic, assign) CGFloat width;
@property(nonatomic, assign) CGFloat height;
@property(nonatomic, assign) CGFloat x;
@property(nonatomic, assign) CGFloat y;

@end
// UIView + LYExtension.m
// Created by YoungLee on **/**/**
// Copyright (c) **** YoungLee.All rights reserved.
#import "UIView + LYExtenson.h"

- (void)setSize:(CGSize)size {
    CGSize size = self.frame;
    frame.size = size;
    self.frame = frame;
}

- (CGSize)size {
    return self.frame.size;
}

- (void)setWidth:(CGFloat)width {
    CGRect frame = self.frame;
    frame.size.width = width;
    self.frame = frame;
}

- (CGFloat)width {
    return self.frame.size.width;
}

- (void)setHeight:(CGFloat)height {
    CGRect frame = self.frame;
    frame.size.height = height;
    self.frame = frame;
}

- (CGFloat)height {
    return self.frame.size.height;
}

- (void)setX:(CGFloat)x {
    CGRect frame = self.frame;
    frame.origin.x = x;
    self.frame = frame;
}

- (CGFloat)x {
return self.frame.origin.x;
}

- (void)setY:(CGFloat)y {
    CGRect frame = self.frame;
    frame.origin.y = y;
    self.frame = frame;
}

- (CGFloat)y {
return self.frame.origin.y;
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,482评论 25 708
  • 可修改、不可修改的集合类;可动态添加修改、不可动态添加修改。 比如NSArray和NSMutableArray,前...
    March_Cullen阅读 431评论 0 1
  • 文//搬砖哥 《无题》 弹指一清烟,起舞弄翩翩。 回首过往事,疑是梦中仙。 少小便离家,常年在天涯。 心中已无苦,...
    一枚搬砖哥阅读 456评论 17 36
  • 太容易喜欢上一个人,不知道是优点还是缺点? 但不太容易被别人喜欢,我知道这个肯定是缺点,至少不是优点。 接触一个人...
    摇月亮阅读 227评论 2 0
  • 每个时期的角色转变都是特别煎熬的,初中上高中,学习强度和压力的角色转换,埋头一整个学期才摸清高中学习的套路。刚上大...
    晨韵风阅读 201评论 0 1