iOS directly changes the control xywidth.height

// 1. Create the category of UIView first 2. Copy the code into it 3. Reference

#import <UIKit/UIKit.h>


@interface UIView (Frame)

@property (nonatomic,assign)CGFloat x;

@property (nonatomic,assign)CGFloat y;

@property (nonatomic,assign)CGFloat width;

@property (nonatomic,assign)CGFloat height;

@property (nonatomic,assign)CGPoint origin;

@property (nonatomic,assign)CGSize size;

@end



@implementation UIView (Frame)


- (void)setX:(CGFloat)x

{

    CGRect frame = self.frame;

    frame.origin.x = x;

    self.frame = frame;

}


- (CGFloat)x

{

    returnself.frame.origin.x;

}


- ( void )setY:( CGFloat )y

{

    CGRect frame = self.frame;

    frame.origin.y = y;

    self.frame = frame;

}


- ( CGFloat )y

{

    returnself.frame.origin.y;

}


- (void)setOrigin:(CGPoint)origin

{

    CGRect frame = self.frame;

    frame.origin = origin;

    self.frame = frame;

}


- (CGPoint)origin

{

    returnself.frame.origin;

}


- (void)setWidth:(CGFloat)width

{

    CGRect frame = self.frame;

    frame.size.width = width;

    self.frame = frame;

}


- (CGFloat)width

{

    returnself.frame.size.width;

}


- (void)setHeight:(CGFloat)height

{

    CGRect frame = self.frame;

    frame.size.height = height;

    self.frame = frame;

}


- (CGFloat)height

{

    returnself.frame.size.height;

}


- (void)setSize:(CGSize)size

{

    CGRect frame = self.frame;

    frame.size = size;

    self.frame = frame;

}


- (CGSize)size

{

    return self.frame.size;

}



@end



    // 使用方法

    UILabel *label = [[UILabelalloc]initWithFrame:CGRectMake(0,80,50, 10)];

    label.text =@"1234564784684864";

    label.height = 20;

    [self.view addSubview:label];






Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325563287&siteId=291194637