UI review, Postgraduate political review
UIButton status
• Normal)
Renewal default
Enumeration constant corresponding to limit: UIControlStateNormal
• Highlighted)
When the finger button is pressed (the finger has not been released)
Enumeration constant corresponding to the condition: UIControlStateHighlighted
• Disabled (invalid or unavailable)
If the enabled attribute is NO, the button is in the disable state, which means the button cannot be clicked.
Enumeration constant corresponding to the marker: UIControlStateDisabled
UIButton and UIImageView
• Similarities: images can be displayed
• Differences
➢ UIButton listens to click events by default, while UIImageView does not
➢ UIButton can display different images in different States
➢ UIButton can display both text and images
• How to choose
➢ UIButton: You need to display the image. After clicking the image, you need to perform some specific operations.
➢ UIImageView: only images need to be displayed. You do not need to do anything after you click images.
Use of NSArray and NSDictionary
• When the image content is very large, the code "set content based on index" is not scalable and must be changed frequently.
• To change the status quo, you can consider saving the image data line to an array with many dictionaries in order,
A dictionary represents an image, including the image name and description.
@ Property (strong, nonatomic) NSArray * images;
• Since image data only needs to be initialized once, it is initialized in the get method.
• The method for initializing attributes in the get method is called "lazy loading" \ "delayed loading"
What is a Plist file?
• Writing data directly in the code is not a reasonable practice. If the data is frequently changed, the corresponding code should be frequently opened for modification, resulting in low code scalability.
• Therefore, you can consider storing frequently changed data in a file for storage. After the program starts, it will read the latest data from the file. To change the data, directly modify the data file without modifying the code.
• Generally, you can use an attribute list file to store data such as NSArray or NSDictionary. The extension of this attribute list file is plist, which becomes a "Plist file"
Procedure
• Define what view is used for each piece
• Define the parent-child relationship between each view
• First try to add grids one by one, and finally consider using a for loop • load app data, create a grid of the corresponding number based on the Data Length • ADD child controls inside the grid
• Assemble data for the child controls inside the grid
Benefits of replacing dictionaries with models
• Disadvantages of dictionary usage
Generally, keys of the string type are used to set and retrieve data. When writing these keys, the compiler does not have any
Friendly reminder, need to be tapped
Dict [@ "name"] = @ "Jack ";
NSString * name = dict [@ "name"];
When you manually press the string key, the key is easy to write incorrectly. If the Key is written incorrectly, the compiler will not receive any warning or error, resulting in incorrect data or incorrect data.
Benefits of using models
The so-called model is actually a data model, which is used to store data objects. It is more professional to use it to represent data.
The model sets and retrieves data through its attributes. If the attribute name is incorrect, the compiler will immediately report an error. Therefore
Verify data correctness
When you use a model to access attributes, the compiler provides a series of prompts to improve the encoding efficiency.
App. name = @ "Jack ";
NSString * name = app. name;
Dictionary-to-Model
• The process of dictionary-to-model conversion is best encapsulated inside the model.
• The model should provide a constructor that can pass in dictionary Parameters
-(Instancetype) initWithDict :( NSDictionary *) dict; Consumer + (instancetype) xxxWithDict :( NSDictionary *) dict;
Instancetype
• Instancetype indicates the type of any object, which is the same as id.
• Instancetype can only be used in the return value type and cannot be used in the parameter type like id
• Instancetype has one more benefit than id: the compiler checks the real type of instancetype
Use of Xib files
• The Xib file can be used to describe a partial UI.
• Xib file loading
Merge method 1
NSArray * objs = [[NSBundle mainBundle] loadNibNamed: @ "MJAppView" owner: nil
Options: nil];
This method will create all objects in the xib and put the objects in the objs array in order (if the xib is shown in the right image, there will be three objects in the objs array in sequence: 1 UIView, 1 UIButton, and 1 UISwitch)
The bundle parameter of method 2 can be nil. The default value is main bundle.
UINib * nib = [UINib nibWithNibName: @ "MJAppView" bundle: [NSBundle mainBundle];
NSArray * objs = [nib instantiateWithOwner: nil options: nil];
• In the development phase, xib files are intended for developers. When an application is installed on a mobile phone, the xib files are converted into nib files.
Adjust view size at will
• To adjust the size of the view in xib at will, you must first set the size to Freeform.
Comparison between Xib and storyboard
• Commonalities:
Description of the software interface.
Interfaces are edited using the Interface Builder tool.
• Differences
➢ Xib is lightweight and used to describe partial UI interfaces.
The elastic Storyboard is a heavyweight tool used to describe multiple interfaces of the entire software and display the jump relationship between interfaces.
View Encapsulation
• If a view contains many sub-controls, you will generally consider customizing a view to block the creation of its internal sub-controls, so as not to concern the outside world
• You can pass in the corresponding model data to the view. After the view obtains the model data, it sets the corresponding data for the internal child control.
Common UILabel settings
• @ Property (nonatomic, copy) NSString
Text displayed by marker
• @ Property (nonatomic, retain) UIFont
Renew font
• @ Property (nonatomic, retain) UIColor
➢ Text color
* Text;
* Font;
* TextColor;
• @ Property (nonatomic) NSTextAlignment textAlignment;
Align alignment mode (such as left alignment, center alignment, and right alignment)
UIFont
• UIFont represents the font. Common creation methods include:
Memory + (UIFont *) systemFontOfSize :( CGFloat) fontSize; default system font
Bytes + (UIFont *) boldSystemFontOfSize :( CGFloat) fontSize; bold
Direction + (UIFont *) italicSystemFontOfSize :( CGFloat) fontSize; Italic
Common UIButton settings
•-(Void) setTitle :( NSString *) title forState :( UIControlState) state;
Text of the "setting" button
• (Void) setTitleColor :( UIColor *) color forState :( UIControlState) state;
Set the text color of the button.
• (Void) setImage :( UIImage *) imageforState :( UIControlState) state;
Small image inside the "resize Settings" button
• (Void) setBackgroundImage :( UIImage *) image forState :( UIControlState) state;
Configure the background image of the button
• Set the text font of the button (you need to get the label inside the button to set it)
Required btn. titleLabel. font = [UIFontsystemFontOfSize: 13];
Common UIButton settings
•-(NSString *) titleForState :( UIControlState) state;
Token to get the text of the button
•-(UIColor *) titleColorForState :( UIControlState) state;
➢ Get the text color of the button
• (UIImage *) imageForState :( UIControlState) state;
➢ Get the small image inside the button
•-(UIImage *) backgroundImageForState :( UIControlState) state;
➢ Get the background image of the button