UIView的類擴充套件,擴充套件CGRect

2021-07-24 23:56:46 字數 2097 閱讀 9293

菜雞成長日記——感慨

剛接觸ios程式設計的時候我們常常會先敲**,同時學習基礎知識,如果是培訓出來的童鞋,由於沒有基礎或者基礎比較薄弱,往往會發現很多知識都沒怎麼理解,這時候自學(從網上找資料)和討論往往能更有效率的獲得知識;
菜雞成長日記——-內容

看到前輩們總是在乙個專案中對uiview進行類方法的擴充套件,具體就是你能看到乙個uiview+cgrrect的檔案(一般這麼命名非常好理解);

而uiview的類擴充套件一般是用於需要改變uiview的位置;

常規方法是先獲取原始uiview的frame,然後對其進行修改,之後再重新賦值給frame;

cgrect frame = self.testview.frame;

frame.size.width = 120;

self.testview.frame = frame;

[self printframe];

如果只是改變一下垂直方向的位置或者寬度和高度之間的乙個,這種寫法就很麻煩了;

如果用類擴充套件,**就會非常簡潔

self.testview.width = 120;

[self printframe];

菜雞成長日記——核心**

這個時候只需要對uiview進行類擴充套件的建立,其他要使用的地方進行標頭檔案引入就可以了。
擴充套件定義:

@inte***ce uiview (resize)

@property (nonatomic, assign) cgsize size;

@property (nonatomic,assign) cgfloat x;

@property (nonatomic,assign) cgfloat y;

@property (nonatomic, assign) cgfloat top;

@property (nonatomic, assign) cgfloat bottom;

@property (nonatomic, assign) cgfloat left;

@property (nonatomic, assign) cgfloat right;

@property (nonatomic, assign) cgfloat centerx;

@property (nonatomic, assign) cgfloat centery;

@property (nonatomic, assign) cgfloat width;

@property (nonatomic, assign) cgfloat height;

@end

擴充套件實現:

@implementation uiview (resize)

– (cgsize)size;

– (void)setsize:(cgsize)size;

–(cgfloat)x

–(void)setx:(cgfloat)x

–(cgfloat)y

–(void)sety:(cgfloat)y

– (cgfloat)left;

– (void)setleft:(cgfloat)x;

– (cgfloat)top;

– (void)settop:(cgfloat)y;

– (void)setright:(cgfloat)right;

– (void)setbottom:(cgfloat)bottom;

– (cgfloat)centerx;

– (void)setcenterx:(cgfloat)centerx;

– (cgfloat)centery;

– (void)setcentery:(cgfloat)centery;

– (cgfloat)width;

– (void)setwidth:(cgfloat)width;

– (cgfloat)height;

– (void)setheight:(cgfloat)height;

@end

Qt 擴充套件 擴充套件部件和外掛程式

qt 擴充套件 擴充套件部件和外掛程式 sf2gis 163.com 2015年1月30日 外掛程式是指由應用程式指定介面,由其它程式實現此介面,並可由應用程式動態載入的實現庫。方法 擴充套件現有部件,擴充套件qt自身外掛程式,擴充套件應用程式的外掛程式,自定義新的控制項。參考 目標 擴充套件qt已...

資料庫表擴充套件 擴充套件屬性

在表的設計時候,由於考慮步驟,需要新增一些字段,重新設計表,但是又不想對錶結構進行大量的改動,其中乙個方法是進行表的擴充套件 假設基礎表為table base 才有三層生成的base bll base dal base model,現在需要進行擴充套件 擴充套件表為table ext,擴充套件表對應...

PHP擴充套件 擴充套件的載入順序及調整

首先找到php擴充套件載入目錄 php i grep extension dir 得到 usr lib64 php modules 那麼這個目錄在 設定的呢?php.ini裡面也沒有啊?我們在編譯安裝擴充套件的時候需要指定 with php config usr bin php config引數,就...