view+stframe 所属Vc


//
//  UIView+STFrame.h
//  yunxinDemo
//
//  Created by 刘小二 on 16/7/13.
//  Copyright © 2016年 刘小二. All rights reserved.
//  快速更改frame OC不允许直接更改 Swift又可以

#import 

@interface UIView (STFrame)

/** self.frame.origion.x */
@property (nonatomic, assign) CGFloat st_left;
/** self.frame.origion.y */
@property (nonatomic, assign) CGFloat st_top;
/**Sets frame.origin.x = st_right - frame.size.width*/
@property (nonatomic, assign) CGFloat st_right;

/**Sets frame.origin.y = bottom - frame.size.height*/
@property (nonatomic, assign) CGFloat st_bottom;

/**Sets self.frame.size.width*/
@property (nonatomic, assign) CGFloat st_width;

/**Sets self.frame.size.height*/
@property (nonatomic, assign) CGFloat st_height;

/**Sets self.center.x */
@property (nonatomic, assign) CGFloat st_centerX;

/**Sets self.center.y */
@property (nonatomic, assign) CGFloat st_centerY;
/**Sets self.frame.origin */
@property (nonatomic, assign) CGPoint st_origin;

/**Sets self.frame.size */
@property (nonatomic, assign) CGSize st_size;

/**
 *  返回当前View对应的控制器
 *
 *  @return 当前View对应的控制器
 */
- (UIViewController *)st_Viewcontroller;

@end



//
//  UIView+STFrame.m
//  yunxinDemo
//
//  Created by 刘小二 on 16/7/13.
//  Copyright © 2016年 刘小二. All rights reserved.
//

#import "UIView+STFrame.h"

@implementation UIView (STFrame)

- (void)setSt_left:(CGFloat)st_left {

    CGRect frame = self.frame;
    
    frame.origin.x = st_left;
    
    self.frame = frame;
}

- (CGFloat)st_left {

    return self.frame.origin.x;
}

- (void)setSt_top:(CGFloat)st_top {

    CGRect frame = self.frame;
    
    frame.origin.y = st_top;
    
    self.frame = frame;

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

- (void)setSt_right:(CGFloat)st_right {

    CGRect frame = self.frame;
    
    st_right = frame.origin.x + frame.size.width;
    
    self.frame = frame;
}

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

- (void)setSt_bottom:(CGFloat)st_bottom {

    CGRect frame = self.frame;
    
    st_bottom = frame.origin.y + frame.size.width;
    
    self.frame = frame;
}

- (CGFloat)st_bottom {
    
    CGRect frame = self.frame;
    
    return frame.origin.y + frame.size.width;
}

- (void)setSt_width:(CGFloat)st_width {

    CGRect frame = self.frame;
    
    frame.size.width = st_width;
    
    self.frame = frame;
}

- (CGFloat)st_width {

    return self.frame.size.width;
}

- (void)setSt_height:(CGFloat)st_height {

    CGRect frame = self.frame;
    
    frame.size.height = st_height;
    
    self.frame = frame;
}

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

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


- (void)setSt_centerX:(CGFloat)st_centerX {
    self.center = CGPointMake(st_centerX, self.center.y);
}

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


- (void)setSt_centerY:(CGFloat)st_centerY {
    self.center = CGPointMake(st_centerY, self.center.y);
}

- (void)setSt_origin:(CGPoint)st_origin {

    CGRect frame = self.frame;
    
    frame.origin = st_origin;
    
    self.frame = frame;
}

- (CGPoint)st_origin {

    return self.frame.origin;
}

- (void)setSt_size:(CGSize)st_size {

    CGRect frame = self.frame;
    
    frame.size = st_size;
    
    self.frame = frame;
}

- (CGSize)st_size {

    return self.frame.size;
}

- (UIViewController *)st_Viewcontroller {

    for(UIView *next = self; next ; next = next.superview) {
    
        if ([[next nextResponder] isKindOfClass:[UIViewController class]]) {
        
        
            return (UIViewController *)[next nextResponder];
        }
    }
    return nil;
    
}
@end


你可能感兴趣的:(view+stframe 所属Vc)