IOS設定frame的時候經常要先取出來-> 設定-> 最後再賦值回去,非常麻煩,今天給大家推薦一種非常快捷的方法

來源:互聯網
上載者:User

標籤:style   http   color   檔案   width   os   

大家可以去我的Githup下載   https://github.com/simplyou/YJ-UIIView-/tree/master

在設定尺寸的時候親們有沒有感覺很蛋疼啊,這裡提供了一套分類,直接放進工程裡,在PCH中包含標頭檔就能解決你蛋疼的問題;

/***********************  .h檔案   ********************************

//  UIView+YJ.h

//  Created by 閃電 on 14-6-8.

//  Copyright (c) 2014年 溫豔軍. All rights reserved.

//  這分類是為瞭解決在OC中設定寬高的問題,提供了一種快捷的方法

#import <UIKit/UIKit.h>

@interface UIView (YJ)

@property (nonatomic, assign) CGFloat x;

@property (nonatomic, assign) CGFloat y;

@property (nonatomic, assign) CGFloat centerX;

@property (nonatomic, assign) CGFloat centerY;

@property (nonatomic, assign) CGFloat width;

@property (nonatomic, assign) CGFloat height;

@property (nonatomic, assign) CGSize size;

@end

 

/*****************************華麗分割線**********************

************************  .m檔案   **********************************

//  UIView+YJ.h

//  Created by 閃電 on 14-6-8.

//  Copyright (c) 2014年 溫豔軍. All rights reserved.

//  這分類是為瞭解決在OC中設定寬高的問題,提供了一種快捷的方法

#import "UIView+YJ.h"

@implementation UIView (YJ)

- (void)setSize:(CGSize)size

{

    CGRect frame = self.frame;

    frame.size = size;

    self.frame = frame;

}

- (CGSize)size

{

    return self.frame.size;

}

- (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;

}

- (void)setCenterX:(CGFloat)centerX

{

    CGPoint center = self.center;

    center.x = centerX;

    self.center = center;

}

- (CGFloat)centerX

{

    return self.center.x;

}

- (void)setCenterY:(CGFloat)centerY

{

    CGPoint center = self.center;

    center.y = centerY;

    self.center = center;

}

- (CGFloat)centerY

{

    return self.center.y;

}

- (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;

}

@end

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.