最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

iOS開發(fā)中Date Picker和UITool Bar控件的使用簡(jiǎn)介

 更新時(shí)間:2016年01月15日 09:29:51   作者:編程小翁  
這篇文章主要介紹了iOS開發(fā)中Date Picker和UITool Bar控件的使用簡(jiǎn)介,代碼基于傳統(tǒng)的Objective-C,需要的朋友可以參考下

一、Date Picker控件
1.簡(jiǎn)單介紹:

201611592936439.png (549×278)

Date Picker顯示時(shí)間的控件
有默認(rèn)寬高,不用設(shè)置數(shù)據(jù)源和代理
如何改成中文的?
(1)查看當(dāng)前系統(tǒng)是否為中文的,把模擬器改成是中文的
(2)屬性,locale選擇地區(qū)
如果默認(rèn)顯示不符合需求。時(shí)間有四種模式可以設(shè)置,在model中進(jìn)行設(shè)置
時(shí)間可以自定義(custom)。
設(shè)置最小時(shí)間和最大時(shí)間,超過就會(huì)自動(dòng)回到最小時(shí)間。
最大的用途在于自定義鍵盤:彈出一個(gè)日期選擇器出來,示例代碼如下:
 
 2.示例代碼

復(fù)制代碼 代碼如下:

//
//  YYViewController.m
//  datepicker
//
//  Created by apple on 14-6-3.
//  Copyright (c) 2014年 itcase. All rights reserved.
//

#import "YYViewController.h"

@interface YYViewController ()
/**
 *  文本輸入框
 */
@property (strong, nonatomic) IBOutlet UITextField *textfield;

@end


復(fù)制代碼 代碼如下:

@implementation YYViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    //1
    //添加一個(gè)時(shí)間選擇器
    UIDatePicker *date=[[UIDatePicker alloc]init];
    /**
     *  設(shè)置只顯示中文
     */
    [date setLocale:[NSLocale localeWithLocaleIdentifier:@"zh-CN"]];
    /**
     *  設(shè)置只顯示日期
     */
    date.datePickerMode=UIDatePickerModeDate;
//    [self.view addSubview:date];
   
    //當(dāng)光標(biāo)移動(dòng)到文本框的時(shí)候,召喚時(shí)間選擇器
    self.textfield.inputView=date;
   
    //2
    //創(chuàng)建工具條
    UIToolbar *toolbar=[[UIToolbar alloc]init];
    //設(shè)置工具條的顏色
    toolbar.barTintColor=[UIColor brownColor];
    //設(shè)置工具條的frame
    toolbar.frame=CGRectMake(0, 0, 320, 44);
   
    //給工具條添加按鈕
        UIBarButtonItem *item0=[[UIBarButtonItem alloc]initWithTitle:@"上一個(gè)" style:UIBarButtonItemStylePlain target:self action:@selector(click) ];
   
        UIBarButtonItem *item1=[[UIBarButtonItem alloc]initWithTitle:@"下一個(gè)" style:UIBarButtonItemStylePlain target:self action:@selector(click)];
   
        UIBarButtonItem *item2=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
        UIBarButtonItem *item3=[[UIBarButtonItem alloc]initWithTitle:@"完成" style:UIBarButtonItemStylePlain target:self action:@selector(click)];
   
     toolbar.items = @[item0, item1, item2, item3];
    //設(shè)置文本輸入框鍵盤的輔助視圖
    self.textfield.inputAccessoryView=toolbar;
}
-(void)click
{
    NSLog(@"toolbar");
}
@end


實(shí)現(xiàn)效果:

201611593003027.png (321×497)

二、UITool Bar
在上面可以添加子控件TOOLBAR中只能添加UIBarButtonItem子控件,其他子控件會(huì)被包裝秤這種類型的
上面的控件依次排放(空格————)
有樣式,可以指定樣式(可拉伸的),一般用來做工具欄。
 
使用toolbar做點(diǎn)菜的頭部標(biāo)題
如何讓點(diǎn)菜系統(tǒng)居中?在ios6中是正的,在ios7中是歪的
在自定義鍵盤上加上一個(gè)工具欄。
數(shù)組里什么順序放的,就按照什么順序顯示
  toolbar.items = @[item0, item1, item2, item3];
    //設(shè)置文本輸入框鍵盤的輔助視圖
    self.textfield.inputAccessoryView=toolbar;

好,讓我們仔細(xì)來看一下UITool Bar的用法。
1.首先,我們看一下UIBbarButtonItem有哪些初始化方法,這也可以看出,它可以被定義為什么東東,然后加到UIToolBar上面去。

根據(jù)SDK的文檔,我們可以發(fā)現(xiàn)UIBarButtonItem有如下幾種初始化的方法:

復(fù)制代碼 代碼如下:

-initWithTitle(添加button用這個(gè))

-initWithImage

-initWithBarButtonSystemItem(添加系統(tǒng)自定義的button,形狀跟大小都已經(jīng)固定了)下面鏈接里面有按鈕圖片樣式

https://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIBarButtonItem_Class/Reference/Reference.html

-initWithCustomView(添加除了button以外的View)


第4種方法就是我們添加各種作料的接口,所以今天的主角其它也是它。

2.在UIToolBar上面添加Title

復(fù)制代碼 代碼如下:

UIToolbar *myToolBar = [[UIToolbar alloc] initWithFrame: 

                                                    CGRectMake(0.0f, 0.0f, 320.0f, 44.0f)]; 

                                                     

NSMutableArray *myToolBarItems = [NSMutableArray array]; 

[myToolBarItems addObject:[[[UIBarButtonItem alloc] 

                                                        initWithTitle:@"myTile"  

                                                        style:UIBarButtonItemStylePlain  

                                                        target:self  

                                                        action:@selector(action)] autorelease]]; 

[myToolBar setItems:myToolBarItems animated:YES]; 

[myToolBar release]; 

[myToolBarItems];                                                        


 

setItems傳入值或者說items是一個(gè)對(duì)象數(shù)組。

3.在UIToolBar上面添加image

復(fù)制代碼 代碼如下:

[myToolBarItems addObject:[[[UIBarButtonItem alloc] 

                                        initWithImage:[UIImage imageNamed:@"myImage.png"]  

                                        style:UIBarButtonItemStylePlain  

                                        target:self  

                                        action:@selector(action)]];  

4.在UIToolBar上面添加SystemItem

[myToolBarItems addObject:[[[UIBarButtonItem alloc] 

                                        initWithBarButtonSystemItem:UIBarButtonSystemItemPlay  

                                        target:self  

                                        action:@selector(action)] autorelease]];  


Note:

initWithBarButtonSystemItem初始化:

復(fù)制代碼 代碼如下:

- (id)initWithBarButtonSystemItem:(UIBarButtonSystemItem)systemItem target:(id)target action:(SEL)action

Defines system defaults for commonly used items.

typedef enum { 

    UIBarButtonSystemItemDone, 

    UIBarButtonSystemItemCancel, 

    UIBarButtonSystemItemEdit, 

    UIBarButtonSystemItemSave, 

    UIBarButtonSystemItemAdd, 

    UIBarButtonSystemItemFlexibleSpace, 

    UIBarButtonSystemItemFixedSpace, 

    UIBarButtonSystemItemCompose, 

    UIBarButtonSystemItemReply, 

    UIBarButtonSystemItemAction, 

    UIBarButtonSystemItemOrganize, 

    UIBarButtonSystemItemBookmarks, 

    UIBarButtonSystemItemSearch, 

    UIBarButtonSystemItemRefresh, 

    UIBarButtonSystemItemStop, 

    UIBarButtonSystemItemCamera, 

    UIBarButtonSystemItemTrash, 

    UIBarButtonSystemItemPlay, 

    UIBarButtonSystemItemPause, 

    UIBarButtonSystemItemRewind, 

    UIBarButtonSystemItemFastForward, 

    UIBarButtonSystemItemUndo,        // iPhoneOS 3.0 

    UIBarButtonSystemItemRedo,        // iPhoneOS 3.0 

} UIBarButtonSystemItem; 


5.在UIToolBar上面添加其它各種控件,最自由意義,最有意思的,我把它放在最后來講。我們使用initWithCustomView來完成,

這里需要看一下initWithCustomView的定義:

復(fù)制代碼 代碼如下:

- (id)initWithCustomView:(UIView *)customView

可以看出,它的參數(shù)是一個(gè)VIEW,所以我們給它的配料要正確哦才行哦,否則,你就等著時(shí)間DIDADIDA的流失吧.

A>加一個(gè)開關(guān)switch:

復(fù)制代碼 代碼如下:

[myToolBarItems addObject:[[[UIBarButtonItem alloc]    

                                initWithCustomView:[[[UISwitch alloc] init] autorelease]] 

                                    autorelease]]; 


B>加一個(gè)按鈕UIBarButtonItem
復(fù)制代碼 代碼如下:

UIBarButtonItem *myButton = [[[UIBarButtonItem alloc] 

                                 initWithTitle:@"myButton" 

                                 style:UIBarButtonItemStyleBordered 

                                 target:self  

                                 action:@selector(action)]autorelease]; 

get1Button.width = 50; 

[myToolBarItems addObject:myButton];     


C>加一個(gè)文本Label
復(fù)制代碼 代碼如下:

view plaincopy to clipboardprint?

UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(40.0f, 20.0f, 45.0f, 10.0f)]; 

myLabel.font=[UIFont systemFontOfSize:10]; 

//myLabel.backgroundColor = [UIColor clearColor]; 

//myLabel.textAlignment=UITextAlignmentCenter; 

UIBarButtonItem *myButtonItem = [[UIBarButtonItem alloc]initWithCustomView:myLabel]; 

[myToolBarItems addObject: myButtonItem];    

[mylabel release]; 

[myButtonItem release]; 


 

D>加一個(gè)進(jìn)度條UIProgressView

復(fù)制代碼 代碼如下:

UIProgressView *myProgress = [[UIProgressView alloc] initWithFrame:CGRectMake(65.0f, 20.0f, 90.0f, 10.0f)]; 

UIBarButtonItem *myButtonItem = [[UIBarButtonItem alloc]initWithCustomView:myProgress]; 

[myToolBarItems addObject: myButtonItem]; 

[myProgress release];                                            

[myButtonItem release]; 


可以加使用initWithCustomView制作各種button,這里就不在這里一個(gè)一個(gè)在加了。我想你應(yīng)該也已經(jīng)掌握了如何添加各種buttonItem的方法了。

相關(guān)文章

  • iOS中長(zhǎng)條藍(lán)色按鈕(button)實(shí)現(xiàn)代碼

    iOS中長(zhǎng)條藍(lán)色按鈕(button)實(shí)現(xiàn)代碼

    本文通過實(shí)例代碼給大家介紹了iOS中長(zhǎng)條藍(lán)色按鈕(button)實(shí)現(xiàn)方法,代碼簡(jiǎn)單易懂,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友參考下吧
    2017-08-08
  • 詳解iOS App開發(fā)中session和coockie的用戶數(shù)據(jù)存儲(chǔ)處理

    詳解iOS App開發(fā)中session和coockie的用戶數(shù)據(jù)存儲(chǔ)處理

    iOS在HTTP網(wǎng)絡(luò)編程環(huán)境方面提供了NSURLSession、NSHTTPCookieStorage和NSHTTPCookie類來處理session和coockie的相關(guān)內(nèi)容,接下來我們將來詳解iOS App開發(fā)中session和coockie的用戶數(shù)據(jù)存儲(chǔ)處理:
    2016-06-06
  • 淺談IOS如何對(duì)app進(jìn)行安全加固

    淺談IOS如何對(duì)app進(jìn)行安全加固

    運(yùn)行在越獄設(shè)備上的IOS app,非常容易遭到破解分析,這里列舉一些可以加大破解難度的方法,希望有所幫助。
    2021-06-06
  • iOS中Cell的Section展開和收起的示例代碼

    iOS中Cell的Section展開和收起的示例代碼

    本篇文章主要介紹了iOS中Cell的Section展開和收起的示例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-08-08
  • iOS中UIScrollView嵌套UITableView的實(shí)踐教程

    iOS中UIScrollView嵌套UITableView的實(shí)踐教程

    在UIScrollView嵌套UITableView的問題相信大家都遇到過,小編最近在工作中就遇到了這個(gè)問題,所以這篇文章主要介紹了iOS中UIScrollView嵌套UITableView的相關(guān)資料,文中介紹的方法是通過自己的實(shí)踐所得來的,需要的朋友可以參考借鑒,下面來一起看看吧。
    2017-05-05
  • iOS實(shí)現(xiàn)UIButton的拖拽功能

    iOS實(shí)現(xiàn)UIButton的拖拽功能

    這篇文章主要為大家詳細(xì)介紹了iOS實(shí)現(xiàn)UIButton的拖拽功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-08-08
  • iOS開發(fā)之路--仿網(wǎng)易抽屜效果

    iOS開發(fā)之路--仿網(wǎng)易抽屜效果

    本文是IOS開發(fā)之路系列的第一篇,主要講訴了如何仿網(wǎng)易新聞客戶端實(shí)現(xiàn)抽屜效果,全部源代碼都分享給大家,希望對(duì)大家有所幫助
    2014-08-08
  • iOS 簡(jiǎn)單的操作桿旋轉(zhuǎn)實(shí)現(xiàn)示例詳解

    iOS 簡(jiǎn)單的操作桿旋轉(zhuǎn)實(shí)現(xiàn)示例詳解

    這篇文章主要為大家介紹了iOS 簡(jiǎn)單的操作桿旋轉(zhuǎn)實(shí)現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-12-12
  • IOS中NSPredicate和NSRegularExpression校驗(yàn)正則表達(dá)式區(qū)別

    IOS中NSPredicate和NSRegularExpression校驗(yàn)正則表達(dá)式區(qū)別

    本文文章通過實(shí)例代碼給大家講述了在IOS開發(fā)中NSPredicate和NSRegularExpression校驗(yàn)正則表達(dá)式區(qū)別,需要的朋友趕快學(xué)習(xí)下吧。
    2018-01-01
  • IOS 靜態(tài)庫(kù)和Framework區(qū)別

    IOS 靜態(tài)庫(kù)和Framework區(qū)別

    這篇文章主要介紹了IOS 靜態(tài)庫(kù)和Framework區(qū)別的相關(guān)資料,這里對(duì)動(dòng)態(tài)庫(kù)與靜態(tài)庫(kù)做比較,選擇什么時(shí)候使用庫(kù)文件,需要的朋友可以參考下
    2016-12-12

最新評(píng)論

武穴市| 新沂市| 金堂县| 丘北县| 普兰店市| 原平市| 梅州市| 沙河市| 峨边| 荆门市| 兴国县| 嘉祥县| 绥宁县| 崇阳县| 融水| 阿瓦提县| 平利县| 陆川县| 霍山县| 湘潭市| 和平县| 甘肃省| 垣曲县| 定陶县| 洪洞县| 枣阳市| 东港市| 甘德县| 辽宁省| 义马市| 普安县| 萝北县| 潮安县| 阳谷县| 营口市| 乐昌市| 化州市| 家居| 枝江市| 夹江县| 温泉县|