Recently learned to do some small purpose of thinking, but also understand and mastered a number of new knowledge. The more in-depth study, the more I feel that learning programming is not easy, those big God, really let me admire.
First, there are three states of UIButton
Normal (normal state) The enumeration constants that correspond to the default conditions: UIControlStateNormal
Highlighted (the highlight state) when the button is pressed down (the finger has not been released) the corresponding enumeration constant: uicontrolstatehighlighted
Disabled (invalid state, unavailable state) if the Enabled property is no, it is in the disable state, which means that the button cannot be clicked on the corresponding enumeration constant: uicontrolstatedisabled
Second, the basic setting of uilable
1, want to let Uilabel automatic line, set lines to 0
2, let the Uilabel text center display
Iii. comparison of UIButton and Uiimageview
Same point: All pictures can be displayed
Different points: UIButton can listen to click events by default, while Uiimageview does not
UIButton can display different pictures in different states
UIButton can display both text and pictures
How to choose UIButton: Need to display pictures, click on the picture need to do some specific actions
Uiimageview: Just need to display the picture, click on the picture, do not need to do anything
Iv. use of Nsarray and nadictionary
1, when the picture content is very long, "set content according to index" code is not extensible, to change the status quo, you can consider to save the picture data to an array, the array is placed in an orderly number of dictionaries, a dictionary representing a picture data, including the picture name, picture description @ Property (Strong, Nonatomic) Nsarray *images;
2, because only need to initialize the picture data once, so put in the Get method to initialize
3, the way the property is initialized in the Get method, called lazy loading \ Deferred loading
V. What is a plist file
It is not a reasonable practice to directly write data directly into the code. If the data is often changed, it is necessary to turn over the corresponding code to modify, resulting in low code extensibility Therefore, you can consider to put the frequently changed data in the file for storage, the program starts to read the latest data from the file. If you want to change the data, directly modify the data file, without modifying the code can generally use the property list file to store Nsarray or nsdictionary, such as data, this property list file extension is plist, so also become "plist file"
Create a plist file
Vi. Analysis of Image.plist
Get the full path of the plist file nsbundle *bundle = [NSBundle mainbundle];
NSString *path = [Bundle pathforresource:@ "ImageData" oftype:@ "plist"];
Load plist file _images = [Nsarray Arraywithcontentsoffile:path];
-(Nsarray *) images{
if (_images = = nil) {
NSBundle *bundle = [NSBundle mainbundle];
NSString *path = [Bundle pathforresource:@ "ImageData" oftype:@ "plist"];
_images = [Nsarray Arraywithcontentsoffile:path];
}
return _images;
}
Vii. Common Properties of UIView
@property (nonatomic) cgrect frame; The position and dimensions of the control's rectangle in the parent control (the origin of the coordinates in the upper-left corner of the parent control)
@property (nonatomic) cgrect bounds; The position and size of the rectangle where the control is located (the origin of the coordinates in its upper-left corner, so the bounds x\y is typically 0)
@property (nonatomic) Cgpoint Center; The position of the midpoint of the control, in the upper-left corner of the parent control, as the coordinate origin.
Eight, UIImage 2 kinds of loading mode
Mode one: There is a cache (the memory occupied by the picture will remain in the program)
+ (UIImage *) imagenamed: (NSString *) name;
Name is the file name of the picture
Mode two: No cache (the memory occupied by the picture will be cleared after some specific operation)
+ (UIImage *) Imagewithcontentsoffile: (NSString *) path-(ID) Initwithcontentsoffile: (NSString *) path;
Path is the full path of the picture
Use models instead of dictionaries
1. Disadvantages of using dictionaries
In general, setting data and fetching data use "String type Key", when writing these keys, the compiler will not have any friendly prompts, need to knock dict[@ "name" = @ "Jack"; NSString *name = dict[@ "name"];
Hand knock string Key,key easy to write wrong key if the error is written, the compiler will not have any warnings and errors, resulting in incorrect data or wrong data
2. Benefits of using Models
The so-called model, in fact, is the data model, specifically used to hold the data of the object, use it to represent the data will be more professional model set up data and take out the data are through its properties, the property name if it is wrong, the compiler will immediately error, therefore, ensure the correctness of the data using the model to access properties, the compiler provides , improve coding efficiency App.name = @ "Jack"; NSString *name = app.name;
3. Attention
The process of dictionary-to-model is best encapsulated in model internal models should provide a construction method that can pass in a dictionary parameter
-(Instancetype) Initwithdict: (Nsdictionary *) dict;
+ (Instancetype) xxxwithdict: (Nsdictionary *) dict;
X. Introduction and use of XIB documents
1. xib file can be used to describe a piece of the local UI interface
2. Loading of xib files
Method 1 Nsarray *objs = [[NSBundle mainbundle] loadnibnamed:@ "Tuappview" Owner:nil Options:nil];
This method creates all the objects in the Xib and places the objects in the OBJS array in order
Method 2 The bundle parameter can be nil, the default is the main bundle uinib *nib = [uinib nibwithnibname:@ "Mjappview" Bundle:[nsbundle Mainbundle]]; Nsarray *OBJS = [nib Instantiatewithowner:nil options:nil];
In the development phase, the developer-oriented is the Xib file; When the app is loaded on the phone, the Xib file is converted to a nib file
3, want to arbitrarily adjust xib in the size of the view, the first to set the size of freeform
4, Xib and storyboard contrast
Common denominator: All used to describe the software interface, all edited using the Interface Builder tool
The difference: Xib is lightweight and is used to describe the local UI interface. Storyboard is a heavyweight, a multi-interface for describing the entire software, and the ability to show jump relationships between multiple interfaces
The end of the love paper-----Some summary of recent learning of iOS development (i)