码迷,mamicode.com
首页 > 移动开发 > 详细

iOS 添加view的分类(更加方便的设置view的位置)

时间:2016-07-21 00:20:16      阅读:318      评论:0      收藏:0      [点我收藏+]

标签:

点击创建UIView的分类category,这里命名为 PLExtension(为了和下面对应)

view分类.h文件

#import <UIKit/UIKit.h>

@interface UIView (PLExtension)
@property (nonatomic, assign) CGFloat WL_width;
@property (nonatomic, assign) CGFloat WL_height;
@property (nonatomic, assign) CGFloat WL_x;
@property (nonatomic, assign) CGFloat WL_y;
@property (nonatomic, assign) CGFloat WL_centerX;
@property (nonatomic, assign) CGFloat WL_centerY;

@property (nonatomic, assign) CGFloat WL_right;
@property (nonatomic, assign) CGFloat WL_bottom;
@end

.m文件

#import "UIView+PLExtension.h"

@implementation UIView (WLExtension)

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

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

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

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

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

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

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

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

- (CGFloat)WL_centerX
{
    return self.center.x;
}

- (void)setWL_centerX:(CGFloat)WL_centerX
{
    CGPoint center = self.center;
    center.x = WL_centerX;
    self.center = center;
}

- (CGFloat)WL_centerY
{
    return self.center.y;
}

- (void)setWL_centerY:(CGFloat)WL_centerY
{
    CGPoint center = self.center;
    center.y = WL_centerY;
    self.center = center;
}

- (CGFloat)WL_right
{
    //    return self.WL_x + self.WL_width;
    return CGRectGetMaxX(self.frame);
}

- (CGFloat)WL_bottom
{
    //    return self.WL_y + self.WL_height;
    return CGRectGetMaxY(self.frame);
}

- (void)setWL_right:(CGFloat)WL_right
{
    self.WL_x = WL_right - self.WL_width;
}

- (void)setWL_bottom:(CGFloat)WL_bottom
{
    self.WL_y = WL_bottom - self.WL_height;
}

@end

  

iOS 添加view的分类(更加方便的设置view的位置)

标签:

原文地址:http://www.cnblogs.com/peaker-wu/p/5689963.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!