iOS learning note is not used with storyboard and some controls in versions above Xcode6

Source: Internet
Author: User
Tags uicontrol

First create a new iOS project, delete the Main.storyboard and xib files that are automatically created by the project, and remove both options on Info.plist

Then set Maninterface to NULL in the project configuration, set launch screen file to null, create a new view, named Viewcontroller, because there is already an auto-generated class Viewcontroller, so you do not have to create a new class

Create a connection to the new Xib file and class, modify the class of the files own to Viewcontroll, and the modifications complete before you proceed to the next step

Connect the View property of the newly created Xib file and to the file own, yes view is associated with the code

At this point, the new xib can generate an interface object.

But you also need to specify which view to use at startup, as follows

Add the following code in the Didfinishlaunchwithoptions method of the APPDELEGATE.M file

  

Self.window = [[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds]];    Viewcontroller* view = [[Viewcontroller alloc] Initwithnibname:@ "viewcontroller" Bundle:nil];     = view;     = [Uicolor whitecolor];    [Self.window makekeyandvisible];

First, to reference the resume Windows, then resume Viewcontroller, set the window's main controller to the generated view, set the background color, and then display the interface

Basically done here, but this kind of practice generated interface may not match, at this time also need in the project configuration of Launch screen file modified to our established main window files, and then start, we can get rid of storyboard

UIButton iOS button control, using UIButton can implement key click Function, the control directly inherits from the Uicontrol class, so has Uicontrol methods and properties, the currently used properties include

Touch up inside event, which is the mouse click event

Gets the text Titleforstate:uicontrolstatenormal method on the current button

Set the background picture that the button is not pressed setbackgroundimage image forstate UIControlStateNormal

Sets the background image that the button is pressed setbackgroundimage image forstate uicontrolstatehighlights

UILabel iOS Text display area

You can use the Text property directly to get the text of the control and to set the text of the control, as well as to format the text

Using nsmutableattributedstring to generate a formatted string, the string uses Setattrbutes to set the property, and Lanbel has a attributetext that can receive the formatted string

Use dictionary when setting font format, dictionary key is text type, value is font size

iOS uses the MVC design pattern, xib as the View view, Viewcontroller as the views controller, and the model is the application delegate, the Appdetegate class, which contains several methods that work in the life cycle of the application

Didfinishlaunchingwithoptions Custom settings after the program starts

The applicationwillresignactive application is about to switch from the active state to the inactive trigger code, in which the referencing program should do its own resource backup

Applicationdidenterbackground application into background execution

Applicationwillenterforeground application into active state, that is, recovering from the background

Applicationdidbecomeactive the application is inactive when it re-enters the active state

Applicationwillterminate the application terminates and the program is about to stop Udiaoyong the method

which

Didfinishlaunchingwithoptions call this method when the application has completed all initialization work and is ready to interact with the user

Active control static controls and passive controls

Passive controls: In most cases, users cannot do anything with them, just a presentation interface, such as the UIImage control, which, of course, is configured to respond to specific events

There are also controls that can work in the passive state, but they do not trigger the method itself, but instead act as a container for data, such as a Uitextfield control.

All iOS controls are subclasses of Uicontrol because the introduction of multi-touch, as well as triggering press and leave, can trigger different methods

All subclasses of UIView have a tag property, which is just a numeric value that can be set in Interface Builder or set in to, and the system never modifies his value, and can be used to easily distinguish between different controls

The Uiimageview control, the control that is used to display a picture, contains the following properties

1.mode determines how content is displayed inside the view, that is, how the image is aligned inside the view, typically using the Scall fill to zoom in and out

2.tag described earlier, the distinction used for the same control

3.interaction contains two options, the first user interaction enable indicates whether the current object can interact with the user, that is, can respond to some methods, multiple touch controls support Multitouch events

4.alpha defines the transparency of the control slice, that is, the visibility of the content behind the image, 0 completely transparent 1 completely opaque

5,background determining the background color of a view

6.drawing contains a series of drawing options opaque tells the system control that there is no picture that needs to be drawn, and allows the system to accelerate the drawing of the control itself. Hidden hiding an object clear Graphics context uses a whole black area to cover the space area before drawing an object clip Subview joins a view that contains a child view, which determines how the child view is drawn and, when selected, Only the part within the parent view is drawn, the outside part is not drawn, unchecked, and the child view is drawn all, regardless of whether the child view exceeds the bounds of the parent view

7.autoresize Subview the size of the child view automatically when the current view changes

8,stretching stretch, which is used when resizing the view, keeping the outer edges of the view intact, stretching only the middle part, rather than stretching the entire contents of the view evenly

Text display the Uilabel control has the following settings properties

1.text: Text display type plaintext plain text attributed Text property

2. Font color settings, text to its settings, line number settings

3.

Text input control Uitextfeild, used for system input text

The text of the 1.placeholder placeholder placeholder is the text that automatically appears when the text of the textbox is empty, and can act as a hint to what the user is entering.

2.border style Sets the border display style of the text box

3.clearbutton settings. When the popup button is set, it can be selected for editing, the editing is done, not appearing, and is visible after the edit, clear when editing begin specifies that the text is cleared when the user touches it, that is, once the edit is started, the previous text input is cleared.

4.adjust to fit: Sets whether the display text decreases as the length of the text size increases, and when selected, all text is visible during the edit process, but the minimum size is not less than the minimum

5. The next step is to define the behavior of the keyboard when typing capitalization use Word to ensure that the first letter of each input word of the user is automatically converted to uppercase, the character that the keyboard displays when the return key user ends the input, autoenable Returnkey Set when the text is empty, return key is disabled

6,secure just whether the input area is a password input area

Finish typing close the keyboard

When an input area such as a text box, when the user presses the return button, the end of the input, an event is triggered, the name is did End on Exit, for the event to set the response method, you can implement the input to complete the automatic shutdown keyboard, such as

-(Ibaction) Textfieldonexit: (ID) sender {    [sender Resignfirstresponder]; // The control itself discards the control of the first responder and returns the control that was manipulated before the user }

But using the numeric keypad to enter the time, there is no return button, you should set the user by the screen without the control of any white space, you can turn off the keyboard, it should be set, touch the background off the keyboard, want to do this, first

First, the base class of the interface is modified to Uicontrol, (previously, UIView), and the modified interface has the ability to respond to events.

To add a touch down event for view, the response function for the event is as follows

[Self.namefield Resignfirstresponder]; [Self.numberfield Resignfirstresponder]; // Free All of the keyboard-occupied places in the view

iOS slide control uislider for showing sliding, main events

ValueChanged The event is triggered when the slider is moved, the current value is obtained by using the Value property, and the maximum and minimum bounds of the value can be controlled

Add top constraints to all spaces when using different screen adaptations, effectively adapting to different device interfaces

The segmented control Uisegmentedcontrol is primarily used to display different content on different interfaces, a control similar to a tab, which can select the number of segments

Select each segment title or each segmented picture, the main response action of the segmented control is also valuechanged, as follows

-(Ibaction) Togglecontrols: (Uisegmentedcontrol *) sender{    if0)//  The current reality is determined by the selectedsegmentindex of the segmented control, and the index    {        = NO is displayed starting at 0 ;         = NO;         = YES;    }     Else     {        = YES;         = YES;         = NO;    }}

Switch control uiswitch for displaying a status Select button that is not 0 or 1

The main response method is valuechanged, as follows

-(Ibaction) switchchanged: (Uiswitch *) sender{    = Sender.ison;   gets the state of the current key, which is a Boolean value    [Self.leftswitch seton:setting animated:yes];   Set switch status according to state     [Self.rightswitch seton:setting animated:yes];    }

iOS action forms and Warning views

The action form is to require the user to choose between more than two options, to manipulate the form from the bottom

Display a series of buttons for the user to select, the user must click on one of the buttons to continue to use, often used to confirm the possible dangerous or irreversible operation,

Using the action form must use the delegate, the user must implement the Uiactionsheetdelegate protocol, as follows

@interface viewcontroller:uiviewcontroller<uiactionsheetdelegate>

Generates and displays the operation of the form

-(Ibaction) buttonpressed: (ID) sender{Uiactionsheet* Actionsheet = [[Uiactionsheet alloc] Initwithtitle:@"Is you sure" Delegate: Self Cancelbuttontitle:@"No"Destructivebuttontitle:@"Yes I am sure"Otherbuttontitles:@"Foo",@"Bar", nil];    [Actionsheet ShowInView:self.view];} 

Initwithtitle uses caption initialization, the first parameter is the caption to be displayed for the action form, a string object, and a delegate object for the second delegate form, when a button of the form is pressed, the corresponding delegate object receives the data, which is specified as self, Cancelbuttontitle the title of the Cancel button Destructivebuttontitle the caption of the button, equivalent to the caption of the confirmation button, Otherbuttontitle: Any number of other buttons, the argument is an array, must end with nil

Then call action Showinview:selfview to specify a parent class for the action form and display it, specifying its own view

At this point, a single action form is displayed.

When used to determine the selection of the action form, that is, when a certain button is pressed, the action form sends a message to the delegate object specified at the time of the build, with the message named Actionsheet, which we inherit

Uiactionsheetdelegate protocol, you must implement the Actionsheet method, as follows
-(void) Actionsheet: (Uiactionsheet *) Actionsheet Diddismisswithbuttonindex: (nsinteger) buttonindex{nsstring* msg =Nil; if(Self.nameField.text.length >0) {msg= [NSString stringWithFormat:@"You can breathe easy,%@,everything went ok.", Self.nameField.text]; }    Elsemsg=@"You can breathe easy,everything went ok."; Uialertview*alert = [[Uialertview alloc] Initwithtitle:@"something was done"Message:msgDelegate: Self Cancelbuttontitle:@"Prew"Otherbuttontitles:nil];    [Alert show]; }

In this method to continue before the processing of the form, the Actionsheet object should also be sent over, index also has, so can get the user pressed position

The warning view is also used in the preceding code to prompt the user for something unusual, and the warning view can display only one button or multiple buttons

Initwithtitle The first is the title of the warning view, the message warning view to display the delegate object for the information processing warning View Cancelbuttontitle The caption of the Cancel button otherbuttontitles the caption of the other button, the array, End With Nil

The warning view is not bound to a specific view, so you do not need to specify a parent view

The Viewdidload method is used in the view class to handle extra settings for views after attempting to load, such as setting the picture background color, and so on

iOS learning note is not used with storyboard and some controls in versions above Xcode6

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.