一. 已學類的繼承關系
Objective-C中所有類的父類為NSObject類
NSObject的子類有:NSString NSArray NSDictionary NSSet NSDate UIGestureRecognizer UIResponder等等
NSString 子類: NSMutableString
NSArray 子類: NSMutableArray
NSDictionary 子類: NSMutableDictionary
NSSet 子類: NSMutableSet
UIGestureRecognizer 子類: UITapGestureRecognizer(輕拍) UISwipeGestureRecognizer(輕掃) UILongPressGestureRecognizer(長按) UIPanGestureRecognizer(平移) UIRotationGestureRecognizer(旋轉) UIPinchGestureRecognizer(捏合)
UIResponder 子類: UIView(視圖) UIApplication AppDelegate UIViewController(視圖控制器)
UIView 子類: UILabel(標簽) UIControl(控制視圖) ?UIImageView UIWindow
UIControl 子類: UIButton UITextField UISlider UIDatePicker UISegmentedControl
UIViewController 子類: UIAlertController
二. UIControl初識
UIControl是具有控制功能的視圖.只要跟控制相關的控件都是其子類.UIControl是個抽象類,通常使用的時候用的都是其子類.
事件響應的三種形式:基于觸摸,基于值,基于編輯
UIControl的子類有:UIButton,UITextField,UISlider,UISwitch,UIDatePicker,UIPageControl,UISegmentedControl
有這幾個子類創建的對象均有
添加一個事件的方法:addTarget:(id) target action:(SEL) forControlEvents:
移除一個事件的方法:removeTarget:(id)target action:(SEL) forControlEvents:
三. UISwitch的使用(開關)
UISwitch繼承于UIControl通常被叫做開關.初始化方法中指定的frame是沒有意義的,系統會指定控件的大小,均為默認值.
onTintColor //設置開啟時的顏色
tintColor //設置開關風格顏色
thumbTintColor //設置開關按鈕顏色
switch.on = YES; //設置開關默認為開啟狀態
四. UISlider的使用(滑塊)
UISlider是iOS中的滑塊控件,通常用于控制視頻播放進度,控制音量等等,繼承于UIControl,滑塊提供了一序列的連續的值,滑塊停在不同的位置,或得滑塊上的值也不同.
UISlider的常用屬性:
minimumValue ?//設置滑塊的最小值,即:滑塊在最左邊的時候的值
maximumValue //設置滑塊的最大值,即:滑塊在最右邊的時候的值
value //設置滑塊的當前值.
minimumTrackTintColor //滑塊劃過的的顏色
maximumTrackTintColor //滑塊未劃過的顏色
同樣的可以添加addTarget action方法.
五. UIDatePicker的使用(擴展)
時間選擇器,創建對象的方式與其他UIControl類的對象創建對象的方式類似.
屬性:
datePickerMode時間選擇器的形式.獲取到的Date可以通過NSDateFormatter對象設置格式控制符控制時間格式,例如:yyyy-MM-dd年-月-日然后通過該類的實例化方法,stirngFromDate方法將date轉化成為字符串.
六. UIAlertController警告對話框 (擴展)
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Tittle" message:@"This is a tittle" preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil];
// 對話框按鈕
UIAlertAction *otherAction = [UIAlertAction actionWithTitle:@"Agree" style:UIAlertActionStyleDefault handler:nil];
// 對話框警示(按鈕為紅色)
UIAlertAction *action = [UIAlertAction actionWithTitle:@"Agree2" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"Press agree2");
}];
//添加對話框上的按鈕
[alertController addAction:otherAction];
[alertController addAction:action];
[alertController addAction:cancelAction];
// 切換視圖控制器
[self presentViewController:alertController animated:YES completion:nil];
七. UISegmentedControl的使用
UISegmentedControl是iOS中常用的分段控件,每個segment都能點擊,它相當繼承了若干個button.分段控件提供一欄按鈕(有時候成為按鈕欄),但一個時刻只能激活一個按鈕.分段控件會導致用戶在屏幕上看到的內容發生變化.它們通常用在不同類別的信息之間選擇,或者在切換不同的視圖.
UISegmentedcontrol屬性以及方法:
initWithItems: //UISegmentedControl獨有的初始化方法.用來創建多個分段
selectedSegmentAtIndex //設定被選中的分段
tintColor //segment的邊框顏色
addTarget方法的時候,處理事件的枚舉為valueChanged方法
通常狀態下,UISegmentedControl的addTarget方法實現中通過switch結合進行
防止圖片被渲染
UIImage *image = [[UIImage imageNamed:imagePath] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
八. UIPageControl的使用
UIPageControl控件是與UIScrollView(滑動視圖)配合顯示大量數據的時候,會用來控制UIScrollView的翻頁.在滾動ScrollView時可以通過PageControl中的小白點來觀察當前頁面的位置,也可以通過pageControl中的小白點來滾動到指定的頁面.
UIPageControl的屬性:
numebrOfPages 頁面的個數
currentPage 選中的點
UIPageControl的addTarget action方法中使用ValueChanged.
UIPageControl的屬性:
currentPageIndicatorTintColor 當前選中點的顏色
pageIndicatorTintColor 其余點的顏色