UI控件

UIApplicationDelegate

/* 说明:当应用程序将要入非活动状态执行,此期间,应用程序不接收消息或事件,比如来电话了 *

- (void)applicationWillResignActive:(UIApplication *)application {}

 

/* 说明:当程序被推送到后台的时候调用。所以要设置后台继续运行,则在这个函数里面设置即可 *

- (void)applicationDidEnterBackground:(UIApplication *)application {}

 

/* 说明:当程序从后台将要重新回到前台时候调用 */

- (void)applicationWillEnterForeground:(UIApplication *)application {}

 

/* 说明:当应用程序入活动状态执行 */

- (void)applicationDidBecomeActive:(UIApplication *)application {}

 

/* 说明:当程序将要退出是被调用,通常是用来保存数据和一些退出前的清理工作。这个需要要设置UIApplicationExitsOnSuspend的键值 */

- (void)applicationWillTerminate:(UIApplication *)application {}

 

/* 说明:当程序载入后执行 */

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{}

 

 

UIViewController

/* 重写初始化方法,完成初始化 */

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{}

 

/* 从nib载入视图,通常这一步不需要去干涉。除非你没有使用xib文件创建视图 */

-(void)loadView{[super loadView];}

 

/* 载入完成,可以进行自定义数据以及动态创建其他控件 */

- (void)viewDidLoad {[super viewDidLoad];}

 

/* 视图将要出现的时候调用 */

-(void)viewWillAppear:(BOOL)animated{}

 

/* 视图已经出现的时候调用 */

-(void)viewDidAppear:(BOOL)animated{}

 

/* 视图将要消失的时候调用 */

-(void)viewWillDisappear:(BOOL)animated{}

 

/* 视图已经消失的时候调用 */

-(void)viewDidDisappear:(BOOL)animated{}

 

/* 当收到内存警告的时候调用 */

- (void)didReceiveMemoryWarning {[super didReceiveMemoryWarning];}

 

 

 

 

 

 

UIView控件

UIWindow

self.window=[[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];//应用程序的窗口,继承自UIView

self.window.backgroundColor=[UIColor whiteColor];//设置窗口的背景颜色

    

    /* 创建一个继承自UIViewController的视图控制器 */

    /**

     RootViewController *rootVC=[[RootViewController alloc]initWithNibName:nil bundle:nil];

     self.window.rootViewController=rootVC;//设置窗口的根视图控制器的属性为firstVC

    **/

 

UIView 

UIView *aView = [[UIView alloc]initWithFrame:CGRectMake(0, 20, 100, 100)];//在定义UIView的时候指定一个坐标

    aView.backgroundColor=[UIColor purpleColor];//设置aView的背景颜色

    [self.view addSubview:aView];

    

    UIView *bView=[[UIView alloc]initWithFrame:CGRectMake(aView.frame.origin.x+50, aView.frame.origin.y+50, 100, 100)];

    bView.backgroundColor=[UIColor blueColor];

    bView.alpha=0.5;//设置透明度

    [self.view addSubview:bView];

 

UILabel

aLabel=[[UILabel alloc]initWithFrame:CGRectMake(20, 200, 280, 40)];

    aLabel.text=@"这只是一个label,真的只是一个label";//设置默认显示文本

    aLabel.backgroundColor=[UIColor greenColor];//设置背景颜色

    aLabel.textAlignment=NSTextAlignmentCenter;//设置文本对齐方式

    aLabel.font=[UIFont systemFontOfSize:20];//设置字号大小(常规)

    aLabel.font=[UIFont boldSystemFontOfSize:20];//设置字号大小(加粗)

    aLabel.numberOfLines=1;//设置文本显示行数

    aLabel.shadowColor=[UIColor blueColor];//设置阴影

    aLabel.shadowOffset=CGSizeMake(1.0, 1.0);//设置阴影宽度

    aLabel.highlightedTextColor=[UIColor blackColor];//设置高亮

    aLabel.highlighted=YES;//设置高亮状态为开

    aLabel.lineBreakMode=NSLineBreakByTruncatingTail;//设置文本过长时显示状态

    [self.view addSubview:aLabel];

 

UIButton

UIButton *yellowButton=[UIButton buttonWithType:UIButtonTypeCustom];//设置按钮样式

    yellowButton.backgroundColor=[UIColor blackColor];//设置按钮的背景颜色

    yellowButton.frame=CGRectMake(200, 50, 100, 40);//设置按钮的坐标以及大小

    [yellowButton setTitle:@"按钮1" forState:UIControlStateNormal];//设置按钮的title,并以常态显示

    [yellowButton addTarget:self action:@selector(setYellowColor) forControlEvents:UIControlEventTouchUpInside];//给按钮添加事件

    [yellowButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];//设置按钮的title颜色

    [yellowButton setBackgroundImage:[UIImage imageNamed:@"按钮素材.png"] forState:UIControlStateHighlighted];//设置按钮高亮点击背景图片

    [self.view addSubview:yellowButton];

    

   NSArray *itemArray=[NSArray arrayWithObjects:@"A",@"B", nil];

   UISegmentedControl

UISegmentedControl *segmentControl=[[UISegmentedControl alloc]initWithItems:itemArray];//初始化一个分段控制器,并给初始的两个按钮

    segmentControl.frame=CGRectMake(20, 280, 280, 30);

    segmentControl.backgroundColor=[UIColor greenColor];//背景颜色

    [segmentControl insertSegmentWithTitle:@"C" atIndex:2 animated:NO];//插入item按钮

    [segmentControl insertSegmentWithTitle:@"D" atIndex:3 animated:NO];

    [segmentControl insertSegmentWithTitle:@"E" atIndex:4 animated:NO];

    

    segmentControl.tintColor=[UIColor redColor];//选中渲染颜色

    [segmentControl setSelectedSegmentIndex:2];//默认选中

    segmentControl.momentary=YES;//设置选中之后是否恢复到原来的状态

    [segmentControl setTitle:@"修改" forSegmentAtIndex:2];//修改标题

    [segmentControl setWidth:100 forSegmentAtIndex:2];//设置字按钮的宽度

    [segmentControl setEnabled:NO forSegmentAtIndex:2];//设置字按钮不可点击

    

    //    titleForSegmentAtIndex//获取字按钮title

    //    imageForSegmentAtIndex//获取字按钮图片

    //    removeSegmentAtIndex: animated://删除一个按钮

    

    [segmentControl addTarget:self action:@selector(chickSegmentControl:) forControlEvents:UIControlEventValueChanged];//添加事件

    [self.view addSubview:segmentControl];

 

-(void)chickSegmentControl:(UISegmentedControl *)segmentC{

    NSInteger index=segmentC.selectedSegmentIndex;

    

    aLabel.text=[segmentC titleForSegmentAtIndex:index];

    

}

 

UISwitch

UISwitch *aSwitch=[[UISwitch alloc]initWithFrame:CGRectMake(30, 320, 100, 30)];

    aSwitch.on=YES;//默认显示状态(开、关)

    aSwitch.onTintColor=[UIColor redColor];//设置打开的颜色

    aSwitch.tintColor=[UIColor orangeColor];//设置关闭的颜色

    aSwitch.thumbTintColor=[UIColor purpleColor];//设置小按钮的颜色

    [aSwitch addTarget:self action:@selector(soSwitch:) forControlEvents:UIControlEventValueChanged];

        [self.view addSubview:aSwitch];

    CGAffineTransform transform1=CGAffineTransformMakeRotation(M_PI/2);

    [aSwitch setTransform:transform1];

 

 

-(void)soSwitch:(UISwitch *)sender

{

    if (sender.on == YES) {

        NSLog(@"switch打开了");

    }

    else

        NSLog(@"switch关闭了");

}    

 

 

UISlider

    UISlider *aSliger=[[UISlider alloc]initWithFrame:CGRectMake(100, 325, 200, 25)];

    aSliger.maximumValue=100;//设置可调整的最大值

    aSliger.minimumValue=0;

    aSliger.maximumTrackTintColor=[UIColor redColor];

    aSliger.minimumTrackTintColor=[UIColor blueColor];

    aSliger.thumbTintColor=[UIColor orangeColor];

    [aSliger addTarget:self action:@selector(doSlider:) forControlEvents:UIControlEventValueChanged];

        [self.view addSubview:aSliger];

   

 -(void)doSlider:(UISlider *)sender

{

    NSLog(@"%f",(float)sender.value);

}

    

UIProgressView

    UIProgressView *progressView=[[UIProgressView alloc]initWithFrame:CGRectMake(20, 365, 280, 10)];

    progressView.progressViewStyle=UIProgressViewStyleBar;

    progressView.progress=0.7;

    progressView.trackTintColor=[UIColor grayColor];

    [self.view addSubview:progressView];

    

    

    UIImageView

    UIImage *image=[UIImage imageNamed:@"run1.tiff"];

    UIImageView *imgView=[[UIImageView alloc]initWithFrame:CGRectMake(20, 380, 160, 120)];

    imgView.image=image;

    

    imgView.animationImages=[NSArray arrayWithObjects:

                             [UIImage imageNamed:@"run1.tiff"],

                             [UIImage imageNamed:@"run2.tiff"],

                             [UIImage imageNamed:@"run3.tiff"],

                             [UIImage imageNamed:@"run4.tiff"],

                             [UIImage imageNamed:@"run5.tiff"],

                             [UIImage imageNamed:@"run6.tiff"], nil];

    imgView.animationDuration=1.0;//一次动画的时间

    imgView.animationRepeatCount=0;//重复的次数,0表示一直重复

    [imgView startAnimating];//开始动画

   [self.view addSubview:imgView];

 

UITextField

    //创建一个文本输入框

    _myTextField=[[UITextField alloc]initWithFrame:CGRectMake(50, 30, 220, 30)];

    _myTextField.backgroundColor=[UIColor whiteColor];//设置背景颜色

    _myTextField.textColor=[UIColor redColor];//设置文字的颜色

    _myTextField.placeholder=@"UITextField";//输入框初始提示的文字(可自定义)

    _myTextField.textAlignment=NSTextAlignmentLeft;//文本对齐方式

    _myTextField.font=[UIFont systemFontOfSize:22];//设置文字的大小

    _myTextField.adjustsFontSizeToFitWidth=YES;//文字自适应

    _myTextField.clearButtonMode=UITextFieldViewModeAlways;//设置出现一个清除按钮

    _myTextField.clearsOnBeginEditing=NO;//设置再次输入自动清除输入框的文本

    _myTextField.delegate=self;//设置自己的代理

    _myTextField.secureTextEntry=YES;//设置每一次输入都变成一个“ · ”

    _myTextField.borderStyle=UITextBorderStyleRoundedRect;//设置输入框的样式

    _myTextField.minimumFontSize=17;//设置自动缩小的最小字体

    _myTextField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;//文本垂直样式

    _myTextField.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;//文本水平样式

    _myTextField.keyboardType=UIKeyboardTypeDefault;//设置键盘样式

    /*

     UIKeyboardTypeDefault,                // 默认键盘

     UIKeyboardTypeASCIICapable,           // 支持ASCII的默认键盘

     UIKeyboardTypeNumbersAndPunctuation,  // 标准的电话键盘(支持+、*、#)

     UIKeyboardTypeURL,                    // 标准的url键盘(有.com)

     UIKeyboardTypeNumberPad,              // 数字键盘

     */

    _myTextField.autocapitalizationType=UITextAutocapitalizationTypeNone;//设置是否首字母大写

    /*

     UITextAutocapitalizationTypeNone,不自动大写

     UITextAutocapitalizationTypeWords,单词的首字母大写

     UITextAutocapitalizationTypeSentences,句子的首字母大写

     UITextAutocapitalizationTypeAllCharacters,所有的字母都大写***???****

     */

    _myTextField.returnKeyType=UIReturnKeyDone;//设置return键变成什么样式

    _myTextField.keyboardAppearance=UIKeyboardAppearanceAlert;//键盘的外观

    UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 40, 40)];

    label.text=@"*";

    _myTextField.leftView=label;

    _myTextField.leftViewMode=UITextFieldViewModeAlways;

    _myTextField.rightView=label;

    _myTextField.rightViewMode=UITextFieldViewModeAlways;

    [self.view addSubview:_myTextField];

UITextFieldDelegate

 

//将要开始编辑  准备编辑

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{

    return YES;

}

//开始编辑

- (void)textFieldDidBeginEditing:(UITextField *)textField{

}

//将要结束编辑

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField{

    return YES;

}

//结束编辑

- (void)textFieldDidEndEditing:(UITextField *)textField{

}

//点击键盘输入调用调用

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{

    return YES;

}

//清空

- (BOOL)textFieldShouldClear:(UITextField *)textField{

    return YES;

}

//换行

- (BOOL)textFieldShouldReturn:(UITextField *)textField{

    [textField resignFirstResponder];//回收键盘 取消第一响应时间

    return YES;

}

 

    

 UITextView

    myTextView=[[UITextView alloc]initWithFrame:CGRectMake(20, 80, 280, 150)];

    myTextView.delegate=self;

    myTextView.font=[UIFont systemFontOfSize:25];

    myTextView.text=@"UITextView,接着写:";

    myTextView.backgroundColor=[UIColor orangeColor];

    myTextView.editable=YES;//可编辑属性

    myTextView.scrollEnabled=YES;//是否可滚动

    myTextView.scrollsToTop=YES;//点击状态栏,返回文本的第一行

    myTextView.showsVerticalScrollIndicator=NO;//展示滚动条

    [self.view addSubview:myTextView];

    UITextViewDelegate

 

/** 单机屏幕其他区域回收键盘 */

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

    UITouch *touch = [[event allTouches]anyObject];

    if (touch.tapCount>=1) {

        [myTextView resignFirstResponder];

    }

}

//文本输入框发生改变时调用(多行)

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{

    if ([text isEqualToString:@"\n"]) {

        [textView resignFirstResponder];

    }

    return YES;

}

UISearchBar

    UISearchBar *searchbar = [[UISearchBar alloc]initWithFrame:CGRectMake(50, 250, 220, 50)];

    searchbar.barTintColor = [UIColor cyanColor];//外围边框颜色

    searchbar.searchBarStyle = UISearchBarStyleDefault;//搜索框风格

    searchbar.tintColor = [UIColor greenColor];//光标颜色

    searchbar.translucent = NO;//是否透明

    searchbar.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters;//设置  大写风格

    searchbar.prompt = @"UISearchBar";//提示

    searchbar.autocorrectionType = UITextAutocorrectionTypeYes;//自动校正

    searchbar.showsBookmarkButton = YES;//展示书签按钮

    searchbar.delegate = self;

    [self.view addSubview:searchbar];

 

UIAlertView

    UIAlertView *alertView1=[[UIAlertView alloc]initWithTitle:@"Warming" message:@"This is a alertview" delegate:nil cancelButtonTitle:@"cancel" otherButtonTitles:@"sure", nil];

    //让提示框展示的方法

    [alertView1 show];

    alertView1.tag=101;//提示框tag值标记

    

    alertView1.title=@"警告";//设置提示框的标题

    alertView1.message=@"还是那个提示框";//设置提示框的提示信息

    

    [alertView1 addButtonWithTitle:@"OK"];//添加提示框展示的按钮

    

    NSLog(@"%d",alertView1.visible);//提示框是否可见的属性(只读)

    NSLog(@"%d",(int)alertView1.numberOfButtons);//获取提示框的按钮的总数

    NSLog(@"%@",[alertView1 buttonTitleAtIndex:0]);//获取提示框制定索引的按钮标题

    NSLog(@"%d",(int)[alertView1 cancelButtonIndex]);//取消按钮的索引

    NSLog(@"%d",(int)alertView1.firstOtherButtonIndex);//第一个按钮的索引

    /*

     UIAlertViewStyleDefault                默认样式

     UIAlertViewStyleSecureTextInput        带有一个 密文 输入框的提示框样式

     UIAlertViewStylePlainTextInput         带有一个 明文 输入框的提示框样式

     UIAlertViewStyleLoginAndPasswordInput  带有两个输入框的提示框样式

     */

    alertView1.alertViewStyle=UIAlertViewStyleLoginAndPasswordInput;

    

    UITextField *textField1=[alertView1 textFieldAtIndex:0];//获取第一个输入框

    textField1.text=@"http://";

    

    UITextField *textField2=[alertView1 textFieldAtIndex:1];//获取第二个输入框

    textField2.placeholder=@"请输密码";

UIAlertViewDelegate

//alertView上面的按钮点击事件

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{

    if (buttonIndex == 1) {

        NSLog(@"sure");

    }

    else

    {

        NSLog(@"cancel");

    }

}

//alertView已经消失的方法

-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex{}

//alertView将要消失的方法

-(void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex{}

//alertView点击取消的方法

-(void)alertViewCancel:(UIAlertView *)alertView{}

//alertView已经出现的方法

-(void)didPresentAlertView:(UIAlertView *)alertView{}

//alertView将要出现的方法

-(void)willPresentAlertView:(UIAlertView *)alertView{

    for (UIView *view in alertView.subviews)

    {

        if ([view isKindOfClass:[UILabel class]])

        {

            UILabel *label=(UILabel *)view;

            label.textAlignment=NSTextAlignmentLeft;

        }

    }

}

 

 

UIActionSheet

    UIActionSheet *actionSheet1=[[UIActionSheet alloc]initWithTitle:@"Actionsheet" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"Red Color" otherButtonTitles:@"Blue Color",@"White Color", nil];

    NSLog(@"%@",[actionSheet1 buttonTitleAtIndex:0]);

    //添加到self.view中

    [actionSheet1 showInView:self.view];

UIActionSheetDelegate

//actionSheet上面的按钮点击事件

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{

    if (buttonIndex==0) {

        self.view.backgroundColor=[UIColor redColor];

    }

    else if (buttonIndex==1)

    {

        self.view.backgroundColor=[UIColor blueColor];

    }

    else

    {

        self.view.backgroundColor=[UIColor whiteColor];

    }

}

//actionSheet将要消失的方法

-(void)actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex{ }

//actionSheet已经消失的方法

-(void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex{

    NSLog(@"已经消失");

}

//取消按钮的方法

-(void)actionSheetCancel:(UIActionSheet *)actionSheet{ }

//actionSheet已经出现的方法

-(void)didPresentActionSheet:(UIActionSheet *)actionSheet{}

//actionSheet将要出现的方法

-(void)willPresentActionSheet:(UIActionSheet *)actionSheet{}

 

UIPickerView

 //UIPickerView选择器的功能,实现数据的选择

    UIPickerView *pickerView1=[[UIPickerView alloc]initWithFrame:CGRectMake(0, 0, 280, 300)];

    pickerView1.center=whiteView.center;

    pickerView1.delegate=self;

    pickerView1.dataSource=self;

    [whiteView addSubview:pickerView1];

 

UIPickerViewDataSource

//返回选择器的列数

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{

    return 2;

}

//返回选择器的行数

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{

    if (component==0) {

        return 6;

    }

    return array.count;

}

 

UIPickerViewDelegate

//返回每一行的标题

-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component

{

    if (component==0) {

        return [NSString stringWithFormat:@"%d",(int)row];

    }

    return [array objectAtIndex:row];

}

//获取单元行的内容

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component

{

    NSString *string=[array objectAtIndex:row];

    NSString *string1=[self pickerView:pickerView titleForRow:row forComponent:0];

    UILabel *getLabel=(UILabel *)[self.view viewWithTag:160];

    NSLog(@"%@--%@",string,string1);

    getLabel.text=string1;

    

}

 

UIDatePicker

//时间的选择器

    UIDatePicker *datepicker=[[UIDatePicker alloc]initWithFrame:CGRectMake(0, 0, 280, 300)];

    datepicker.tag=175;

    datepicker.center=whiteView.center;

    datepicker.date=[NSDate date];//设置时间选择器的显示时间为当前时间

    datepicker.datePickerMode=UIDatePickerModeDateAndTime;

    [whiteView addSubview:datepicker];

UIDatePicker 选中的事件

-(void)selectDatePicker:(UIButton *)sender

{

    UIDatePicker *datePicker=(UIDatePicker *)[self.view viewWithTag:175];

    NSDateFormatter *formatter=[[NSDateFormatter alloc]init];

    formatter.dateFormat=@"YYYY-MM-dd hh:mm:ss aaa";

    

    UILabel *getLabel=(UILabel *)[self.view viewWithTag:165];

    getLabel.text=[formatter stringFromDate:datePicker.date];

    

}

 

 

UIScrollView1

    UIImageView *imgView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 770, 180)];

    imgView.image=[UIImage imageNamed:@"Beautiful.jpeg"];

    

    UIScrollView *_scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(20, 30, 280, 180)];

    _scrollView.contentSize=CGSizeMake(770, 180);//有效的显示区域

    _scrollView.backgroundColor=[UIColor redColor];

   [_scrollView addSubview:imgView];

    

    UILabel *addLabel=[[UILabel alloc]initWithFrame:CGRectMake(300, 30, 150, 30)];

    addLabel.backgroundColor=[UIColor orangeColor];

    addLabel.text=@"多么美的一幅画啊";

    [_scrollView addSubview:addLabel];

    

    _scrollView.pagingEnabled=NO;//分页显示的效果

   [_scrollView setContentOffset:CGPointMake(300, 0) animated:YES];//加载后横向滚动300像素

   _scrollView.scrollEnabled=YES;//是否可以滚动的属性

   _scrollView.userInteractionEnabled=YES;//设置交互的属性

   _scrollView.showsHorizontalScrollIndicator=YES;

   _scrollView.showsVerticalScrollIndicator=YES;//设置滚动条是否显示

   _scrollView.bounces=NO;//设置边界的反弹效果

   [self.view addSubview:_scrollView];

 

    UIScrollView2+UIPageControl

    int weigth=700*280/1066;

    UIScrollView *myScollview=[[UIScrollView alloc]initWithFrame:CGRectMake(65, 250, weigth, 280)];

    myScollview.backgroundColor=[UIColor redColor];

    myScollview.contentSize=CGSizeMake(weigth*5, 280);

    myScollview.tag=121;

    myScollview.delegate=self;

    for (int i=0; i<5; i++) {

        UIImageView *imgView1=[[UIImageView alloc]initWithFrame:CGRectMake(weigth*i, 0, weigth, 280)];

        NSString *imgName=[NSString stringWithFormat:@"image%d.jpeg",i];

        imgView1.image=[UIImage imageNamed:imgName];

        [myScollview addSubview:imgView1];

    }

    myScollview.pagingEnabled=YES;

   [self.view addSubview:myScollview];

    

    UIPageControl *pageControl=[[UIPageControl alloc]initWithFrame:CGRectMake(0, 215, 320, 30)];

    pageControl.tag=122;

    pageControl.backgroundColor=[UIColor blueColor];

    pageControl.numberOfPages=5;//控制显示的页数

    pageControl.currentPage=0;//默认显示在第几页

 

    [pageControl addTarget:self action:@selector(pageControlSelector:) forControlEvents:UIControlEventValueChanged];

    [self.view addSubview:pageControl];

 

-(void)pageControlSelector:(UIPageControl *)sender

{

    NSLog(@"%d",(int)sender.currentPage);

    UIScrollView *getScroll=(UIScrollView *)[self.view viewWithTag:121];

    

    CGSize size=getScroll.frame.size;

    

    CGRect rect1=CGRectMake((sender.currentPage * size.width), 0, size.width, size.height);

    [getScroll scrollRectToVisible:rect1 animated:YES];//让scrollveiw滚动

    

    

}

 -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView

{

    UIPageControl *pageC=(UIPageControl *)[self.view viewWithTag:122];

    

    CGPoint point1=scrollView.contentOffset;

    NSLog(@"%f",(float)point1.x);

    

    [pageC setCurrentPage:point1.x/183];

    

    

}

 

UIWebView

_webView=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, 320, 400)];

    _webView.delegate=self;

    NSString *urlString=@“http://www.baidu.com”;声明网址字符串

    NSURL *url=[NSURL URLWithString:urlString];//将字符串封装到NSUrl中用于访问

    NSURLRequest *request=[[NSURLRequest alloc]initWithURL:url];//建立网络请求对象,用于请求服务器

    [_webView loadRequest:request];//开始执行访问方法

    [self.view addSubview:_webView];

 

if ([_webView canGoBack]) {[_webView goBack];}//如果可以返回网页,就返回

if ([_webView canGoForward]) {[_webView goForward];}//如果可以前进网页,就前进

 

UIWebViewDelegate

//已经开始加载的方法

  • (void)webViewDidStartLoad:(UIWebView *)webView{}

//已经完成加载的方法

  • (void)webViewDidFinishLoad:(UIWebView *)webView{}

//发生错误的方法

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error

{NSLog(@“发生错误 %@“,error.localizedDescription);}

 

UIToolbar

UIToolbar *toolBar=[[UIToolbar alloc]initWithFrame:CGRectMake(20, 40, 280, 40)];

    toolBar.backgroundColor=[UIColor redColor];

    

    //创建toolBar上面的单元按钮

    UIBarButtonItem *item1=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self action:@selector(doItemOne)];

    UIBarButtonItem *item2=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:@selector(doItemTwo)];

    UIBarButtonItem *item3=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:self action:@selector(doItemThree)];

    UIBarButtonItem *item4=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:self action:@selector(doItemFour)];

   

    //添加均等分割的空格

    UIBarButtonItem *itemSpace=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];

    

    [toolBar setItems:@[item1,itemSpace,item2,itemSpace,item3,itemSpace,item4]];//将创建好的按钮放在toolBar上

    

    toolBar.tintColor=[UIColor blueColor];//添加元素的颜色

   toolBar.barTintColor=[UIColor orangeColor];//工具条的颜色

   toolBar.barStyle=UIBarStyleBlackTranslucent;//设置工具条的样式

   [self.view addSubview:toolBar];

 

在键盘上添加回收键盘的工具条

    UIToolbar *returnBar=[[UIToolbar alloc]initWithFrame:CGRectMake(20, 100, 280, 40)];

    UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];

    button.frame=CGRectMake(0, 0, 40, 30);

    [button setImage:[UIImage imageNamed:@"jianpan.png"] forState:UIControlStateNormal];

    [button addTarget:self action:@selector(doReturnKeybord) forControlEvents:UIControlEventTouchUpInside];

    UIBarButtonItem *returnBTN=[[UIBarButtonItem alloc]initWithCustomView:button];//将自定义的按钮封装成UIBarButtonItem对象

    returnBar.barTintColor=[UIColor blackColor];

    [returnBar setItems:@[itemSpace,returnBTN]];

    [self.view addSubview:returnBar];

    

    UITextField *ttytt;

    ttytt.inputAccessoryView=returnBar;//将工具条添加到输入框弹出的键盘上

posted @ 2015-12-07 19:30  开心刘哈哈  阅读(209)  评论(0编辑  收藏  举报