//
//  UIView+frame.m
//  SmartLightForBigFish
//
//  Created by coderYK on 2017/8/9.
//  Copyright © 2017年 RD-iOS. All rights reserved.
//

#import "UIView+frame.h"

@implementation UIView (frame)

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

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

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

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

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

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

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

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

-(void)setRds_centerX:(CGFloat)rds_centerX
{
    CGPoint center = self.center;
    center.x = rds_centerX;
    self.center = center;
}

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

-(void)setRds_centerY:(CGFloat)rds_centerY
{
    CGPoint center = self.center;
    center.y = rds_centerY;
    self.center = center;
}

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

- (CGFloat)rds_right {
    return self.frame.origin.x + self.frame.size.width;
}

- (void)setRds_right:(CGFloat)rds_right {
    CGRect frame = self.frame;
    frame.origin.x = rds_right - frame.size.width;
    self.frame = frame;
}

- (CGFloat)rds_bottom {
    return self.frame.origin.y + self.frame.size.height;
}

- (void)setRds_bottom:(CGFloat)rds_bottom {
    CGRect frame = self.frame;
    frame.origin.y = rds_bottom - frame.size.height;
    self.frame = frame;
}

- (CGPoint)rds_origin {
    return self.frame.origin;
}

- (void)setRds_origin:(CGPoint)rds_origin {
    CGRect frame = self.frame;
    frame.origin = rds_origin;
    self.frame = frame;
}

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

- (void)setRds_size:(CGSize)rds_size {
    CGRect frame = self.frame;
    frame.size = rds_size;
    self.frame = frame;
}

+ (CGFloat)rds_statusBarHeight{
    CGFloat statusBarHeight = 0;
    if (@available(iOS 13.0, *)) {
        statusBarHeight = [UIApplication sharedApplication].windows.firstObject.windowScene.statusBarManager.statusBarFrame.size.height;
    } else {
        statusBarHeight = [UIApplication sharedApplication].statusBarFrame.size.height;
    }
    return statusBarHeight;
}

+ (CGFloat)rds_tabBarHeight{
    CGFloat tabBarHeight = [UIView rds_statusBarHeight] > 20? 83:49;
    return tabBarHeight;
}

- (void)removeAllSubviews {
    while (self.subviews.count) {
        UIView* child = self.subviews.lastObject;
        [child removeFromSuperview];
    }
}
@end
