I will share my experience in encapsulating iOS custom controls. I will attach the Demo & lt; time selector & amp; multi-line input box & amp; Date selector & gt;, iosdemo

Source: Internet
Author: User

I will share my experience in encapsulating iOS custom controls. I will attach the Demo of three easy-to-use controls <time selector & multi-line input box & date selector> and iosdemo

Some time ago, some friends asked me, "What should I do with such controls? ", I think it is a relatively simple control. It may not be very clear about the idea of the comrades who entered the line soon. If you are not busy with your recent work, let's share some of my experience in encapsulating custom controls.

A good custom control can greatly reduce the code in the controller, so that the code is clear at the level where it should be. In addition, a custom control without coupling can be used in any subsequent projects to improve development efficiency. User-friendly, easy to use, non-coupling, clear and easy to maintain code layers are essential to a good control. Common Custom Controls in projects are usually pop-up windows for users to conveniently view, input, select, and perform other operations.

The following shows the code and Train of Thought Analysis of the Three recently encapsulated controls.

 

I. Time Selector

1. Usage: Call the show method first, and then define the callback block.

2. effect: the control is added with Time Filtering (time 12-09), and the last selection is memorized, without coupling.

3. Train of Thought Analysis: My friend asked me about the control, which was used in such a scenario: the user asked about time experts to select a time point through this control. My ideas are as follows:

1) analysis interface (view ):

The toolbar is displayed on the page. The left and right buttons are switched to the previous day/next day, and the lable in the middle shows the date and the day of the week. Let's look at the 12 buttons in the middle. Each button represents a certain time point. There are three styles: clickable status, unclickable status, and selected status, in the Demo, I used buttons for implementation. Using collectionView should make the code more concise.

At the same time, you need to consider that every time a user switches to another day, the control needs to be refreshed, according to the new day, the expert idle time (the server returns ), to refresh the display style of the 12 buttons in the middle [available/unavailable/currently selected].

2) data analysis (model ):

First, analyze the data required for the current day. We need to tell the user which time points the expert can make an appointment and which cannot be made, and use a field to represent it, there are a total of 12 time points, that is to say, each display of this control requires an array of 12 elements. These 12 elements correspond to whether the reservation can be made at these 12 time points.

Suppose we allow the user to reserve a range for the next week, then this control requires a large array containing seven sub-arrays, each of which has 12 elements, it is the data that experts can make appointments on a certain day. Yes, so the controller needs to give this control a large array.

3) event handling for Button clicking on the previous day/next day:

For more analysis, see the Demo.

 

Ii. Custom multi-line input box

1. Usage: first set the data, then call the show method, and finally define the callback block.

2. effect: the mobile phone number and email detection method are added to the control without coupling. The method of illegal prompting is also suitable.

3. train of Thought Analysis: this control is very simple and easy to use. The control will display several lines of input Boxes Based on the imported data, the Data Validity Check and keyboard processing are performed internally... there is nothing to say about the idea...

 

Iii. Date Selector

1. Usage: Call the show method first, and then define the callback block.

2. effect: a prompt is added to the control for simple time judgment and illegal selection. The callback block is called only when the time is valid and the valid time string is passed out.

3. Train of Thought Analysis: Well, this control is simpler...

 

Iv. Summary

When I get the design drawing, the first step is to analyze what controls should be on the interface, analyze what data needs to be passed by the Controller, and then put the properties to be exposed in the H file, attributes that do not need to be exposed are stored in the m file. The custom control I encapsulate has been trying to do the following:

1. User-friendly and easy to use. "Show" means "show" and "hide" means "hide". You do not need a controller to display or hide the code. The controller only needs to tell me when to show and when to hide.

2. The encapsulation reduces the code in the controller. The Controller only needs to care about what data, how to show you, and how to handle hide and click events. Instead of worrying about how you display and process data.

 

Demo github address: https://github.com/banchichen/SomeGoodCustomView

You are welcome to share your commonly used custom controls... you are also welcome to criticize and correct the flaws...

 

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.