UIVIew:
1、UIView的概念:ide
UIView表示屏幕上的一塊矩形區域,它在App中佔有絕對重要的地位,由於IOS中幾乎全部可視化控件都是UIView的子類。負責渲染區域的內容,而且響應該區域內發生的觸摸事件
UIView的功能 1.管理矩形區域裏的內容2.處理矩形區域中的事件3.子視圖的管理 4.還能實現動畫 UIView的子類也具備這些功能 學習
2、UIView的基本用法:
一、UIView的初始化:
UIView *view = [[UIView alloc]initWithFrame:CGRectMack(x,y,width,height)]; 字體
其中:CGRect :CGPoint (x,y) CGSize:(width,height)
CGFloat :單門給UI界面用的float類型。動畫
例如:CGRectMake(10, 10, 200, 200);
二、UIView的相關代碼:UIColor :
初始化(固定生成方式):UIColor *color = [UIColor redColor] ;
三原色方式: UIColor *color2 = [UIColor colorWithRed:0.3 green:0.2 blue:0.1 alpha:1];
alpha :透明度;orm
RGB:red、green、biue 三原色 範圍0-1;
三、管理view層次的方法對象
view - view2,view3教程
bringSubviewToFront - 把某個子界面放到最前事件
[self.view1 bringSubviewToFront:view2];圖片
sendSubviewToBack - 把某個子界面放到最後ip
[self.view1 sendSubviewToBack:view2];
inster - 按照index調整位置
[view insertSubview:view3 atIndex:0];
裁剪子view到父view大小
self.view1.clipsToBounds = YES;
UIButton(按鈕):
1、UIButton的概念:
UIButton按鈕是IOS開發中最經常使用的控件,做爲IOS基礎學習教程知識 ,初學者須要瞭解其基本定義和經常使用設置,以便在開發在熟練運用。
2、UIButton的基本用法:
一、UIButton的初始化:
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
UIButtonTypeCustom 默認色是白色,記得設置顏色
其餘的初始化方法:
UIButtonTypeCustom - 自定義
UIButtonTypeSystem - 系統自帶樣式
UIButtonTypeDetailDisclosure - 小歎號
UIButtonTypeContactAdd - 小加號
二、UIbutton的設置:
(1)設置標題
UIControlStateNormal - 正常狀態
UIControlStateHighlighted - 點擊中ing
UIControlStateDisabled - 不可點擊
UIControlStateSelected - 已選中狀態
設置狀態就是一種提早方案
[btn setTitle:@"我是按鈕" forState:UIControlStateNormal];
[btn setTitle:@「按鈕是誰" forState:UIControlStateHighlighted];
更改不可選狀態
enabled - 是否容許用戶點擊
btn.enabled = YES;
(2)設置按鈕字體大小和顏色
btn.titleLabel.font = [UIFont systemFontOfSize:20];
[btn setTitleColor:[UIColor orangeColor] forState:UIControlStateHighlighted];
[btn setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
設定按鈕大小位置
btn.frame = CGRectMake(100, 100, 100, 100);
(3)設置點擊事件
給button添加一個點擊事件
addTarget - 響應的對象
action - 具體的響應方法 @selector()
forControlEvents - UIControlEventTouchUpInside 點擊了按鈕的正中央,在中間擡起來
[btn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
}
:(UIButton *)btn 參數能夠不寫,通常加上
- (void)clickBtn:(UIButton *)btn
{
。。。
}
(4)用圖片當Button的背景
UIImage *image_normal = [UIImage imageNamed:@"buttongreen"];
setImage forState :在什麼狀態下顯示什麼圖片
[btn setImage:image_normal forState:UIControlStateNormal];
UIImage *image_hi = [UIImage imageNamed:@"buttongreen_highlighted"];
[btn setImage:image_hi forState:UIControlStateHighlighted];
[btn setTitle:@"我是按鈕" forState:UIControlStateNormal];
[btn setTitle:@"按鈕是誰" forState:UIControlStateHighlighted];
setImage - setTitle :
setBackgroundImage :圖片當作背景,文字在上面
[btn setBackgroundImage:image_normal forState:UIControlStateNormal];
[btn setBackgroundImage:image_hi forState:UIControlStateHighlighted];