Introduction to the use of the date picker and Uitool bar controls in IOS development _ios

Source: Internet
Author: User
Tags documentation

One, Date picker control
1. Brief introduction:

Date picker control that displays the time
There are default widths, no data source and proxy settings
How to change it into Chinese?
(1) To see if the current system is Chinese, change the simulator to Chinese
(2) attribute, locale Select region
If the default display does not meet the requirements. There are four modes of time to set up and set in model
Time can be customized (custom).
Set the minimum time and maximum time, more than will automatically return to the minimum time.
The biggest purpose is to customize the keyboard: Pop up a date selector, sample code as follows:

2. Sample Code

Copy Code code as follows:

//
Yyviewcontroller.m
DatePicker
//
Created by Apple on 14-6-3.
Copyright (c) 2014 itcase. All rights reserved.
//

#import "YYViewController.h"

@interface Yyviewcontroller ()
/**
* Text Input Box
*/
@property (Strong, nonatomic) Iboutlet Uitextfield *textfield;

@end


Copy Code code as follows:

@implementation Yyviewcontroller

-(void) viewdidload
{
[Super Viewdidload];
1
Add a time picker
Uidatepicker *date=[[uidatepicker Alloc]init];
/**
* Settings Show only Chinese
*/
[Date Setlocale:[nslocale localewithlocaleidentifier:@ "ZH-CN"]];
/**
* Set display date only
*/
Date.datepickermode=uidatepickermodedate;
[Self.view Addsubview:date];

When the cursor is moved to the text box, call the time picker
Self.textfield.inputview=date;

2
Create a tool bar
Uitoolbar *toolbar=[[uitoolbar Alloc]init];
To set the color of a tool bar
Toolbar.bartintcolor=[uicolor Browncolor];
Set the frame of a tool bar
Toolbar.frame=cgrectmake (0, 0, 320, 44);

To add a button to a tool bar
Uibarbuttonitem *item0=[[uibarbuttonitem alloc]initwithtitle:@ "prev" Style:uibarbuttonitemstyleplain target:self Action: @selector (click)];

Uibarbuttonitem *item1=[[uibarbuttonitem alloc]initwithtitle:@ "Next" Style:uibarbuttonitemstyleplain target:self Action: @selector (click)];

Uibarbuttonitem *item2=[[uibarbuttonitem Alloc]initwithbarbuttonsystemitem:uibarbuttonsystemitemflexiblespace Target:nil Action:nil];
Uibarbuttonitem *item3=[[uibarbuttonitem alloc]initwithtitle:@ "complete" Style:uibarbuttonitemstyleplain target:self Action: @selector (click)];

Toolbar.items = @[item0, Item1, item2, Item3];
Set up a secondary view of the Text entry box keyboard
Self.textfield.inputaccessoryview=toolbar;
}
-(void) Click
{
NSLog (@ "toolbar");
}
@end


Implementation effect:

Second, Uitool Bar
You can add a child control above toolbar only add Uibarbuttonitem child controls, other child controls will be wrapped scale this type of
The controls above are emitted sequentially (spaces ————)
Style, you can specify a style (which can be stretched), generally used to make a toolbar.

Use toolbar to make a la carte head title
How do I get a la carte system centered? In the IOS6 is positive, in the iOS7 is crooked
Add a toolbar to your custom keyboard.
In what order the array is placed, and in what order it is displayed.
Toolbar.items = @[item0, Item1, item2, Item3];
Set up a secondary view of the Text entry box keyboard
Self.textfield.inputaccessoryview=toolbar;

OK, let's take a closer look at the usage of Uitool bar.
1. First, let's take a look at Uibbarbuttonitem's initialization methods, which can also be seen to define why, and then add it to the Uitoolbar.

According to the SDK documentation, we can see that Uibarbuttonitem has the following initialization methods:

Copy Code code as follows:

-initwithtitle (add button with this)

-initwithimage

-initwithbarbuttonsystemitem (Add System custom button, shape and size are already fixed) the link below has a button picture style

https://developer.apple.com/library/ios/#documentation/uikit/reference/uibarbuttonitem_class/reference/reference.html

-initwithcustomview (add view other than button)


The 4th method is that we add the various condiments of the interface, so today's protagonist other is it.

2. Add title to Uitoolbar

Copy Code code as follows:

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 incoming values or items are an array of objects.

3. Add image above Uitoolbar

Copy Code code as follows:

[Mytoolbaritems Addobject:[[[uibarbuttonitem Alloc]

Initwithimage:[uiimage imagenamed:@ "Myimage.png"]

Style:uibarbuttonitemstyleplain

Target:self

Action: @selector (Action)]];

4. Add Systemitem to Uitoolbar

[Mytoolbaritems Addobject:[[[uibarbuttonitem Alloc]

Initwithbarbuttonsystemitem:uibarbuttonsystemitemplay

Target:self

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


Note:

Initwithbarbuttonsystemitem initialization:

Copy Code code as follows:

-(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. Add a variety of other controls above the Uitoolbar, the most free and most interesting, I put it in the end. We use Initwithcustomview to do it,

Here you need to look at the definition of Initwithcustomview:

Copy Code code as follows:

-(ID) Initwithcustomview: (UIView *) CustomView

It can be seen that its parameters is a view, so we give it the ingredients to be correct oh, otherwise, you will wait for the loss of time Didadida.

A> plus a switch:

Copy Code code as follows:

[Mytoolbaritems Addobject:[[[uibarbuttonitem Alloc]

Initwithcustomview:[[[uiswitch alloc] init] autorelease]]

Autorelease]];


B> plus a button uibarbuttonitem
Copy Code code as follows:

Uibarbuttonitem *mybutton = [[[Uibarbuttonitem Alloc]

initwithtitle:@ "MyButton"

Style:uibarbuttonitemstylebordered

Target:self

Action: @selector (Action)]autorelease];

Get1button.width = 50;

[Mytoolbaritems Addobject:mybutton];


C> plus a text label
Copy Code code as follows:

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> plus a progress bar Uiprogressview

Copy Code code as follows:

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


You can use Initwithcustomview to make a variety of button, this is not here one in addition. I think you also have mastered how to add various Buttonitem methods.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.