1. Frame
每個視圖都有一個frame屬性,它是CGRect結構,它描述了視圖所在的矩形在其父視圖中的位置。
(屏幕坐標系默認的原點在左上角,x軸向右伸展,y軸向下伸展)
設置frame通常通過視圖的指定初始化器initWithFrame
下面來看個例子,該例子初始化了3個相互疊加的矩形區(qū)域
(Objective-C代碼)
UIView* v1 = [[UIView alloc] initWithFrame:CGRectMake(113, 111, 132, 194)]; v1.backgroundColor = [UIColor colorWithRed:1 green:.4 blue:1 alpha:1]; UIView* v2 = [[UIView alloc] initWithFrame:CGRectMake(41, 56, 132, 194)]; v2.backgroundColor = [UIColor colorWithRed:.5 green:1 blue:0 alpha:1]; UIView* v3 = [[UIView alloc] initWithFrame:CGRectMake(43, 197, 160