iOS開發 很有用的UIView分類

2022-09-08 05:06:08 字數 2695 閱讀 5221

很有用的uiview分類,可以用來方便訪問檢視座標x,y,中心點,寬度和高度等等

uiview+category.h

1

#import23

ib_designable45

@inte***ce

uiview (category)

6@property (nonatomic, assign)cgfloat x;

7@property (nonatomic, assign)cgfloat y;

8@property (nonatomic, assign)cgfloat width;

9@property (nonatomic, assign)cgfloat height;

10@property (nonatomic, assign)cgfloat centerx;

11@property (nonatomic, assign)cgfloat centery;

12@property (nonatomic, assign)cgsize size;

13@property(nonatomic, assign) ibinspectable cgfloat borderwidth;

14 @property(nonatomic, assign) ibinspectable uicolor *bordercolor;

15@property(nonatomic, assign) ibinspectable cgfloat cornerradius;

1617/**

18* 水平居中

19*/

20 - (void

)alignhorizontal;

21/**22

* 垂直居中

23*/

24 - (void

)alignvertical;

25/**26

* 判斷是否顯示在主視窗上面27*

28* @return 是否

29*/

30 -(bool)isshowonwindow;

3132 - (uiviewcontroller *)parentcontroller;

33@end

uiview+category.m

1

#import

"uiview+category.h"2

3@implementation

uiview (category)

45 - (void

)setx:(cgfloat)x611

12 -(cgfloat)x

1316

17 - (void

)sety:(cgfloat)y

1823

24 -(cgfloat)y

2528

29 - (void

)setwidth:(cgfloat)width

3035

36 -(cgfloat)width

3740

41 - (void

)setheight:(cgfloat)height

4247

48 -(cgfloat)height

4952

53 - (void

)setsize:(cgsize)size

5459

60 -(cgsize)size

6164

65 - (void

)setcenterx:(cgfloat)centerx

6671

72 -(cgfloat)centerx

7376

77 - (void

)setcentery:(cgfloat)centery

7883

84 -(cgfloat)centery

8588 - (void

)alignhorizontal

8992

93 - (void

)alignvertical

9497

98 - (void

)setborderwidth:(cgfloat)borderwidth

99104 self.layer.borderwidth =borderwidth;

105}

106107 - (void)setbordercolor:(uicolor *)bordercolor

108111

112 - (void

)setcornerradius:(cgfloat)cornerradius

113117

118 -(bool)isshowonwindow

119else

134}

135136 -(cgfloat)borderwidth

137140

141 - (uicolor *)bordercolor

142146

147 -(cgfloat)cornerradius

148151

152 - (uiviewcontroller *)parentcontroller

153159 responder =[responder nextresponder];

160}

161return

nil;

162}

163164

165@end

iOS開發 很有用的UIView分類

很有用的uiview分類,可以用來方便訪問檢視座標x,y,中心點,寬度和高度等等 uiview category.h 1 import23 ib designable45 inte ce uiview category 6 property nonatomic,assign cgfloat x 7 ...

iOS開發 UIView動畫

ios 動畫 uiview動畫 原文 1.概述 uikit直接將動畫整合到uiview類中,實現簡單動畫的建立過程。uiview類定義了幾個內在支援動畫的屬性宣告,當這些屬性發生改變時,檢視為其變化過程提供內建的動畫支援。執行動畫所需要的工作由uiview類自動完成,但仍要在希望執行動畫時通知檢視,...

iOS開發 UIView中的座標轉換

將畫素point由point所在檢視轉換到目標檢視view中,返回在目標檢視view中的畫素值 cgpoint convertpoint cgpoint point toview uiview view 將畫素point從view中轉換到當前檢視中,返回在當前檢視中的畫素值 cgpoint conv...