美文网首页iOS Developer
ios UI控件的简单整理(6)

ios UI控件的简单整理(6)

作者: 蜗蜗牛在奔跑 | 来源:发表于2017-04-21 09:24 被阅读41次

    > #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];

    相关文章

      网友评论

        本文标题:ios UI控件的简单整理(6)

        本文链接:https://www.haomeiwen.com/subject/mcarzttx.html