ios UI控件的簡單整理(6)

> #pragma mark - UIToolbar// 工具欄(在工具欄上可以放導航專用按鈕)UIToolbar *tb = [[UIToolbar alloc] initWithFrame:CGRectMake(0,20,320,44)];[self.viewaddSubview:tb];UIBarButtonItem*editBtn =[[UIBarButtonItemalloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:selfaction:@selector(editClick:)];// UIBarButtonSystemItemFlexibleSpace專用按鈕占位符// 在工具欄展示一些專用按鈕tb.items= @[editBtn, refreshBtn];#pragma mark - UISearchBar_sb = [[UISearchBaralloc] initWithFrame:frame];// 整個表格視圖可以擁有一個頭view_myTableView.tableHeaderView= _sb;// 搜索控制器(將_sb和頁面關聯起來)_sdc = [[UISearchDisplayController alloc] initWithSearchBar:_sb contentsController:self];_sdc.delegate=self;// 給搜索控制器自帶的tableView設置代理_sdc.searchResultsDataSource=self;_sdc.searchResultsDelegate=self;// 只要_sb里的文字發生了改變,都會執行該方法- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString*)searchString{? ? [_resultArr removeAllObjects];for(NSArray*arr in _myDataArr) {for(NSString*str in arr) {NSRangerange = [str rangeOfString:searchString];if(range.length>0) {? ? ? ? ? ? ? ? [_resultArr addObject:str];? ? ? ? ? ? }? ? ? ? }? ? }returnYES;}#pragma mark - 定時器和延時調用//創建定時器,每隔幾秒就運行某個函數一次NSTimer *_timer = [NSTimer scheduledTimerWithTimeInterval:0.01target:selfselector:@selector(run) userInfo:nilrepeats:YES];// 相當于上面一行_timer = [NSTimer timerWithTimeInterval:1.0target:selfselector:@selector(update:) userInfo:nilrepeats:YES];[[NSRunLoop currentRunLoop] addTimer:_timer forMode:NSDefaultRunLoopMode];//取消定時器(定時器取消后,必去重新初始化)[_timer invalidate];// self會在2秒以后執行runLater:方法,同時把sender作為參數[selfperformSelector:@selector(runLater:) withObject:sender afterDelay:0.5];#pragma mark - 常用基本控件#pragma mark UISlider// 滑尺控件UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(40,60,240,90)];[self.viewaddSubview:slider];// 滑尺一般情況下我們是監控ValueChanged事件// 可以添加多個監聽事件[slider addTarget:selfaction:@selector(sliderClick:) forControlEvents:UIControlEventValueChanged];// ValueChanged事件對應的消息在滑動過程中是否接收slider.continuous=NO;// 最小和最大記錄的值(記錄范圍)slider.maximumValue=10;slider.minimumValue=0;// 通過代碼設置滑塊的值slider.value=5;// 左右線條的顏色slider.maximumTrackTintColor= [UIColorblackColor];slider.minimumTrackTintColor= [UIColorgreenColor];// 設置小圓圈(拇指)圖片[slider setThumbImage:[UIImageimageNamed:@"gerenzhuye"] forState:UIControlStateNormal];#pragma mark UISegmentedControl// 使用數組初始化分段選擇器(可以是字符串,也可以是圖片,圖片默認被渲染)UISegmentedControl*segmentControl = [[UISegmentedControlalloc] initWithItems:[NSArrayarrayWithObjects:@"111", [[UIImageimageNamed:@"gerenzhuye"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal],@"222",nil]];segmentControl.frame= CGRectMake(40,200,240,60);[segmentControl addTarget:selfaction:@selector(segmentedControlClick:) forControlEvents:UIControlEventValueChanged];// 刪除一個分段[segmentControl removeSegmentAtIndex:1animated:YES];// 插入一個分段(可以是字符串或者圖片)[segmentControl insertSegmentWithTitle:@"333"atIndex:2animated:YES];// 設置默認點擊分段segmentControl.selectedSegmentIndex=1;// 設置渲染色segmentControl.tintColor= [UIColorredColor];// 獲取分段的位置編號// 獲取分段的標題sc.selectedSegmentIndex;[sc titleForSegmentAtIndex:sc.selectedSegmentIndex];#pragma mark UISwitch// 開關控件,大小是固定的51*31,自己設定無效UISwitch *open = [[UISwitch alloc] initWithFrame:CGRectMake(40,80,100,100)];// 拇指,關閉時邊框,打開時背景的顏色open.thumbTintColor= [UIColorredColor];open.tintColor= [UIColorblackColor];open.onTintColor= [UIColorblueColor];// 默認打開狀態open.on=YES;#pragma mark UIActivityIndicatorView// 使用某種風格初始化活動指示器(自帶大小)UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];// 開始旋轉[indicator startAnimating];// 一般都是放置在屏幕正中間indicator.center=self.view.center;// 設置小菊花顏色indicator.color= [UIColoryellowColor];// 用系統提供的單例方法獲取到程序剛運行時創建的UIApplication對象// 系統狀態欄自帶的旋轉小菊花[UIApplicationsharedApplication].networkActivityIndicatorVisible=YES;#pragma mark UIWebView// 將字符串轉成網址類對象NSURL*url = [NSURLURLWithString:str];// 使用一個網址生成一個網絡請求NSURLRequest*request = [NSURLRequestrequestWithURL:url];// 讓一個網頁視圖開始加載一個網絡請求[webView loadRequest:request];// 允許頁面縮放webView.scalesPageToFit=YES;- (void)reload;- (void)stopLoading;- (void)goBack;- (void)goForward;#pragma mark UIStepper// 計步器,大小固定94*29,設置大小無效UIStepper *stepper = [[UIStepper alloc] initWithFrame:CGRectMake(40,60,200,40)];// 計步器每次改變的大小stepper.stepValue=30;// 設置最小和最大的記錄stepper.minimumValue=10;stepper.maximumValue=300;// 設置渲染色stepper.tintColor= [UIColorredColor];// 設置加號和減號的圖片[stepper setIncrementImage:[UIImageimageNamed:@"haoyou"] forState:UIControlStateNormal];[stepper setDecrementImage:[UIImageimageNamed:@"liaotian"] forState:UIControlStateNormal];#pragma mark UIProgressView// 進度條(展示用的)高度固定位2UIProgressView *pv = [[UIProgressView alloc] initWithFrame:CGRectMake(20,300,280,80)];[pv setProgress:(sender.value-10)/290.0animated:YES];#pragma mark? UIAlertView// alertView的點擊事件(必須遵守協議,成為代理才能響應)// 如果一個頁面有多個av,在點擊事件里,需要先通過av的tag值區分出點擊的是哪一個av,然后再通過buttonIndex區分出點擊了av的哪一個按鈕UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"標題"message:@"信息"delegate:selfcancelButtonTitle:@"取消"otherButtonTitles:@"其他",@"其他2",nil];[av show];// 代理一般實現方法- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;// 添加文本輸入框av.alertViewStyle= UIAlertViewStyleLoginAndPasswordInput;#pragma mark UIActionSheet// 創建一個事件列表UIActionSheet *as = [[UIActionSheet alloc] initWithTitle:@"title"delegate:selfcancelButtonTitle:@"cancel"destructiveButtonTitle:@"dt"otherButtonTitles:@"qq", @"weixin", @"weibo",nil];// 展示的view必須是出現在window里的[as showInView:self.view];

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容