[PickerView Case 11-Customized Keyboard Operation 01 Objective-C Language]

1. UIDatePicker - date selection control

1. In the last lesson, we have already implemented this national flag selection, right?

Then, there is our date selection control, UIDatePicker

notify

Custom View, are you already familiar with it?

So, we won’t say any more,

Next, let’s take a look at the second control.

UIDatePicker,

In the morning, we just gave a brief introduction. In the afternoon, we used it to do some things.

Well, first of all, it’s the same. Let’s take a look at its case first.

notify
notify

Click this "13-Day 1 (application startup principle).xcodeproj"

Open this project:

notify

Then, select the 4th Target: UIDatePicker

notify

command + R:

notify

Is there a text box here? Then, after clicking on this text box:

notify

Do you see, usually after we click on the text box, what should it look like?

What is displayed is a keyboard, right?

But what is displayed here? Are they some dates? You can choose.

1) Click cancel: nothing happens

2) Click Confirm:

notify

Put the corresponding time on it,

The interface below is implemented by our UIDatePicker.

notify

What about the one in the middle? I’ll explain it to you later.

Okay, first of all, let’s take a look,

2.UIDatePicker control:

notify

UIDatePicker: The main purpose is to facilitate users to select dates and times.

What I just saw is a date?

When you go down to write, you can also consider using some time, that’s fine too.

Usually presented as inputView of TextField,

What does the inputView of TextField look like?

For example, this is a mobile interface:

notify

Above, there is a text box:

notify

By default, after we click on this text box, it will pop up a keyboard for you.

As for the keyboard, there are probably just this:

notify

Everyone knows the height of the keyboard, it is probably 216.

That’s the height of 216,

By default, when you click on the text box, a keyboard will pop up, and then you can enter text, numbers, etc.

But what if you improve this text box's inputView, our inputView here?

That's not it,

What about this word, inputView:

notify

input: What does it mean, input?

View: Well, it’s just an input interface.

Input view, input interface:

notify

Then, the view is our control, right?

UIView type controls,

Then, the input view, an input control,

If you put it as inputView, set it up,

After that, what interface do you put on it?

Then what interface does it display?

You hand UIDatePicker to it,

Then, when you click on the text box, the DatePicker pops up.

Instead of the system keyboard,

Also, inputView, there is another thing,

inputAccessory

notify

Let me move this thing out.

inputAccessoryView: What is this?

notify

This is on the keyboard, with a strip tied to it:

notify

A strip tied to the keyboard:

notify

Accessory: Have you seen this before? Accessory, what is it?

Is it an auxiliary view?

that inputAccessoryView: input auxiliary view,

Just draw it here, probably on our keyboard, probably at such a high position:

notify

If you set a view, estimate its height.

Then, it can be displayed. Of course, if you increase the height, it may become reality, or it may become higher:

notify

Then, there is such a view,

When you click on the text box, both of them will pop up,

If you set inputView and inputAccessoryView at the same time,

As for the two of them, they just popped up together.

If you only set the inputView, then only the keyboard is replaced.

In other words, the "Cancel, Confirm" you just saw is placed on top of it.

Let’s come back and continue:

notify

This UITextField is introduced to you here.

Well, this is about usage, so I won’t talk about it.

I’ll talk about it later when I write the code,

notify

Talk to you later,

notify

4.NSDateFormatter: Have we used it before?

So, here we don’t look any further.

1) If you convert date to string: there is a [formatter stringFromDate:]

Date: Is it just the date?

String: Well, is it just a string?

stringFromDate: Convert from date to string,

2) The return is the same: [formatter dateFromString:]

Convert a string into a date,

Right,

Okay, those are the two points. Next, our goal is to implement a custom keyboard for this text box:

notify

However, I need to add something to this above: "cancel and confirm".

What about the one above?

1) First: "Cancel, Confirm", is it a commonly used button?

But, where should I put this button? In the inputAccessoryView of the text box,

However, it is not put directly on it.

It requires the use of another control,

Let's take a look together,

2. Create a new project

notify

1. Select this: New-Project,

Select this Single View Application:

notify

Name: 08-custom keyboard datePicker:

notify

Okay, let’s go to Main.storyboard first:

notify

Let’s experience it first:

notify

Let me show you those two strips first:

notify

Where are the two words "Cancel and Confirm" placed?

I put this Window:stay in Front:

notify

I put this window at the front.

Okay, first of all, "Cancel and Confirm", these two things are not the Button we commonly use.

We need to use a new control called: UIButtonItem.

There is nothing difficult about this thing. It is just a button, but the type is different:

notify

See no: UIButtonItem,

Just use it as a button, no problem.

OK, just a button,

Click it, and there will be some operations. However, it has a characteristic, that is, it cannot be included in any View. It needs to be placed in a UIToolbar or UINavigationItem.

1) This UINavigationItem: You don’t have to worry about it, we will learn this tomorrow,

This is a navigation bar,

2) This UIToolbar: This is what we have here:

notify

Use this thing behind this,

A gray, light gray effect,

2. Then, let’s create a UIToolbar first and show it to everyone.

So UIToolbar: Which one is UIToolbar?

notify

This is our thing with Edit,

Did you see: UIToolbar,

It's not difficult at all, it's just a strip.

Then, inside, there are some function buttons.

However, this button does not mean that you can move any button upward.

One must be: UIButtonItem,

Because the things placed are all one: instance of UIButtonItem,

The toolbar items it writes: are actually the UIButtonItems inside.

notify

3. Let’s look at them one by one. Let’s look at this UIToolbar first:

notify

Drag UIToolbar: up,

notify

Put it here:

notify

Put it directly in here,

Do you see it:

notify

This is a UIToolbar,

As for the one next to it, I put it in the back.

notify

This is UIToolbar: the abbreviation is Toolbar, do you see it?

It’s not difficult, it’s just a View.

However, the system packaged it for us,

Abbreviation: called UIToolbar,

And what about these things inside:

notify

It's not an ordinary button, but it's a ButtonItem.

Take a look at its type:

notify

See no: UIBarButtonItem:

notify

No problem, it’s actually just a button. You can also click it normally to perform some operations.

Then, you can also drag another ButtonItem to it:

notify

Two ButtonItems:

notify

Then, let me change the title of the thing on the left to be the same as our button:

notify

In it, you either specify text or pictures, but you cannot specify both at the same time.

I changed it to "Cancel"

notify

Over here, I changed it to "Done"

notify

I drag another BarButtonItem,

notify

As for this BarButtonItem, place it between them:

notify

Then, this thing, we have in this text box:

notify

After clicking, are Cancel and Confirm at both ends?

Then everyone said, how to put this?

Do I need to put it here or there?

I can't delay this "completion":

notify

If it can't be dragged away, it will go back on its own:

notify

However, you can select the BarButtonItem in the middle. Then, there are some system types that you should have seen before.

For example, let's look at the others:

notify

The following are all types of systems.

Then, there is "Add"

Guess you like

Origin blog.csdn.net/madoca/article/details/133016029
Recommended