Basic knowledge of IOS development-fragment 50, basic knowledge of ios-Fragment

Source: Internet
Author: User

Basic knowledge of IOS development-fragment 50, basic knowledge of ios-Fragment

 

1: Two or more Masonry controls are sorted at intervals.

 

/*** Multiple controls are arranged at regular intervals, the length or width of the control is changed ** @ param axisType axis direction * @ param fixedSpacing interval size * @ param leadSpacing header interval * @ param tailSpacing tail interval */-(void) interval :( MASAxisType) axisType withFixedSpacing :( CGFloat) fixedSpacing l eadSpacing :( CGFloat) leadSpacing tailSpacing :( CGFloat) tailSpacing;/*** multiple fixed-size controls are arranged at intervals, the difference is the gap ** @ param axisType axis direction * @ param fixedItemLength the fixed length or width value of each control * @ param leadSpacing header interval * @ param tailSpacing tail interval */- (void) mas_distributeViewsAlongAxis :( MASAxisType) axisType withFixedItemLength :( CGFloat) fixedItemLength leadSpacing :( CGFloat) leadSpacing tailSpacing :( CGFloat) tailSpacing;

It is easy to use because it is an NSArray class extension:

// Create two or more initialized controls in the horizontal arrangement icon arr. // The alongAxis axis is fixed at intervals. The header is separated by the tail interval. [arr mas_distributeViewsAlongAxis: MASAxisTypeHorizontal withFixedSpacing: 20 leadSpacing: 5 tailSpacing: 5]; [arr makeConstraints: ^ (MASConstraintMaker * make) {make. top. similar to (@ 60); make. height. similar to (@ 60);}];

Instance:

       NSMutableArray *mutableArr = [[NSMutableArray alloc] initWithCapacity:6];        for (int i=0; i<3; i++) {            UIButton *button = [[UIButton alloc] init];            [button setTitle:strArr[i] forState:UIControlStateNormal];            [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];            button.layer.borderColor = [UIColor blackColor].CGColor;            [button addTarget:self action:@selector(show:) forControlEvents:UIControlEventTouchUpInside];            button.layer.borderWidth = 2;            [self addSubview:button];            [mutableArr addObject:button];        }                [mutableArr mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:20 leadSpacing:20 tailSpacing:20];                [mutableArr mas_makeConstraints:^(MASConstraintMaker *make) {                    make.top.equalTo(@120);                    make.height.equalTo(@75);                }];

 

2: simple use of YYLabel

NSString * title = @ "I have to say that the third-party framework of YYKit is really awesome. YYLabel is quite powerful in rich text display and operations, especially its asynchronous rendering, making the interface smoother and smoother, here we will introduce the simple use of "; // YYLabel Rich Text YYLabel * titleLabel = [YYLabel new]; // asynchronous rendering when a label displays a huge amount of text, it can clearly feel the powerful titleLabel of this function. displaysAsynchronously = YES; [self. view addSubView: titleLabel]; titleLable. numOfLines = 0; YYTextContainer * titleContarer = [YYTextContainer new]; // The specified width is detailContarer. size = CGSizeMake (100, CGFLOAT_MAX); optional * titleAttr = [self getAttr: title]; YYTextLayout * layout = [YYTextLayout layout: titleContarer text: titleAttr]; CGFloat layout = titleLayout. textBoundingSize. height; titleLabel. frame = CGRectMake (50, 50, 100, titleLabelHeight );
-(NSMutableAttributedString *) getAttr :( NSString *) attributedString {NSMutableAttributedString * resultAttr = [[NSMutableAttributedString alloc] initWithString. yy_alignment = NSTextAlignmentJustified; // set the row spacing resultAttr. yy_lineSpacing = 5; // set the font size of resultAttr. yy_font = [UIFont systemFontOfSize: bytes]; // you can set the font size of a specific segment. // [resultAttr yy_setFont: [UIFont character: CONTENT_FONT_SIZE] range: NSMakeRange (0, 3)]; // set the word spacing // resultAttr. yy_kern = [NSNumber numberWithFloat: 1.0]; return resultAttr ;}

3: appStore version number detection and update instance

// 1 you must first configure your project's APPID in the store. It is best to run it on the real machine to see the complete effect! # Define STOREAPPID @ "1104867082" @ interface ViewController () @ end @ implementation ViewController * tianchao detection app update */-(void) hsUpdateApp {// 2 first obtain the current project version number NSDictionary * infoDic = [[NSBundle mainBundle] infoDictionary]; NSLog (@ "% @", infoDic ); NSString * currentVersion = infoDic [@ "cfbundle‑versionstring"]; // 3 obtain the appStore version number NSError * error from the network; NSData * response = [NSURLConnection sendSynchronousRequest: [NSURLRequ Est requestWithURL: [NSURL URLWithString: [NSString stringWithFormat: @ "http://itunes.apple.com/cn/lookup? Id = % @ ", STOREAPPID] returningResponse: nil error: nil]; if (response = nil) {NSLog (@" You are not connected to the network "); return;} NSDictionary * appInfoDic = [NSJSONSerialization JSONObjectWithData: response options: Internal error: & error]; if (error) {NSLog (@ "hsUpdateAppError: % @", error ); return;} // NSLog (@ "% @", appInfoDic); NSArray * array = appInfoDic [@ "results"]; if (array. count <1) {NSLog (@ "This APPID is not "); Return;} NSDictionary * dic = array [0]; NSString * appStoreVersion = dic [@" version "]; // print the version NSLog (@ "current version: % @ \ n store version: % @", currentVersion, appStoreVersion); // set the version number currentVersion = [currentVersion stringByReplacingOccurrencesOfString :@". "withString: @" "]; if (currentVersion. length = 2) {currentVersion = [currentVersion stringByAppendingString: @ "0"];} else if (currentVersion. length = 1) {CurrentVersion = [currentVersion stringByAppendingString: @ "00"];} appStoreVersion = [appStoreVersion stringByReplacingOccurrencesOfString :@". "withString: @" "]; if (appStoreVersion. length = 2) {appStoreVersion = [appStoreVersion stringByAppendingString: @ "0"];} else if (appStoreVersion. length = 1) {appStoreVersion = [appStoreVersion stringByAppendingString: @ "00"];} // 4 if the current version is earlier than the store version, update if ([curren TVersion floatValue] <[appStoreVersion floatValue]) {UIAlertController * alercConteoller = [UIAlertController updated: @ "version updated" message: [NSString stringWithFormat: @ "New Version Detected (% @), update? ", Dic [@" version "] preferredStyle: Custom]; UIAlertAction * actionYes = [UIAlertAction actionWithTitle: @" Update "style: UIAlertActionStyleDefault handler: ^ (UIAlertAction * _ Nonnull action) {// here add the application address in the app store for users to update, an implementation method is as follows NSURL * url = [NSURL URLWithString: [NSString stringWithFormat: @ "https://itunes.apple.com/us/app/id%? Ls = 1 & mt = 8 ", STOREAPPID]; [[UIApplication sharedApplication] openURL: url] ;}]; UIAlertAction * actionNo = [UIAlertAction actionWithTitle: @" cancel "style: incluhandler: ^ (UIAlertAction * _ Nonnull action) {}]; [alercConteoller addAction: actionYes]; [alercConteoller addAction: actionNo]; [self presentViewController: incluanimated: YES completion: nil];} else {NSLog (@ "version number seems bigger than the store! No need to update detected ");}}

4: three handshakes and four handshakes in the TCP protocol (illustration)

Note: The two vertical lines on the left and right are in different States, and the two vertical lines in the middle are transmitted.

 

Three-way handshake:

First, the Client sends a connection request message. The Server segment replies to the ACK packet after accepting the connection and allocates resources for the connection. After the Client receives the ACK packet, it also generates an ACK packet to the Server segment and allocates resources so that the TCP connection is established.

 

Four handshakes:

Assume that the Client initiates an interrupt connection request, that is, sending a FIN packet. After the Server receives the FIN message, it means "I have no data to send to you on the Client". However, if you still have data to be sent, you do not have to rush to close the Socket, you can continue sending data. So you should first send ACK, "tell the Client that I have received your request, but I am not ready yet. Please continue waiting for my message ". At this time, the Client enters the FIN_WAIT status and continues to wait for the Server's FIN message. When the Server determines that the data has been sent, it sends a FIN message to the Client, "tell the Client, okay, I have sent the data, and I am ready to close the connection ". After the Client receives the FIN message, it will know that the connection can be closed, but he still does not trust the network, for fear that the Server does not know that the connection should be closed, so after the ACK is sent, it enters the TIME_WAIT status, if the Server does not receive an ACK, it can be re-transmitted. ", After the Server receives the ACK," you will know that you can disconnect ". After the Client waits for 2MSL, it still does not receive a reply, proving that the Server has been shut down normally. Well, the Client can also close the connection. OK. The TCP connection is closed!

 

1. Physical Layer: It mainly defines physical device standards, such as the interface type of the network cable, the interface type of the optical fiber, and the transmission rate of various transmission media. Its main function is to transmit the bit stream (that is, the conversion from 1, 0 to the current strength for transmission, after reaching the destination is converted to 1, 0, that is, the digital-to-analog conversion and digital-to-analog conversion ). The data at this layer is called bits.

2. data link layer: defines how to format data for transmission and how to control access to physical media. This layer usually provides error detection and correction to ensure reliable data transmission.

3. Network Layer: Provides the connection and path selection between two host systems in a network located in different geographic locations. The development of Internet greatly increases the number of users accessing information from various sites in the world, and the network layer is the layer for managing such connections.

4. transmission Layer: defines some data transmission protocols and port numbers (WWW port 80, etc.), such as TCP (transmission control protocol, low transmission efficiency, high reliability, high transmission reliability requirements, large data volume), UDP (User Datagram Protocol, which is the opposite of TCP, is used to transmit data with low reliability requirements and small data volume, for example, QQ chat data is transmitted in this way ). Data received from the lower layer is segmented and transmitted, and then reorganized after the destination address is reached. This layer of data is often called segments.

5. Session Layer: establishes a data transmission path through the transport layer (port number: Transmission port and receiving port. It is mainly used to initiate a session or receive a session request between your systems (devices need to know each other, either an IP address, a MAC address, or a host name)

6. Presentation Layer: ensure that the information sent by the application layer of one system can be read by the application layer of another system. For example, a PC program communicates with another computer, one of which uses an extended Gbit/s Exchange Code (EBCDIC), and the other uses an American Standard ASCII code (ASCII) to indicate the same characters. If necessary, the presentation layer uses a common format to convert multiple data formats.

7. Application Layer: the OSI Layer closest to the user. This layer provides network services for your applications (such as email, file transfer, and terminal simulation.

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.