Mobile development-Summary of iOS development code

Source: Internet
Author: User

We can see that the csdn blog channel has a great essay activity on "iOS game programming Journey", mainly because it prefers signature books. So I will summarize the small code developed by IOS and share it with you.

1. Image Upload code that can be used after testing

-(Ibaction) uploadbutton :( ID) sender {uiimage * image = [uiimage imagenamed: @ "1.jpg"]; // image name nsdata * imagedata = uiimagejpegrepresentation (image, 0.5 ); // compression ratio nslog (@ "Bytes: % I", [imagedata length]); // Post URL nsstring * urlstring = @ "http: // 192.168.1.113: 8090/text/uploadservlet "; // server address // setting up the request object now nsmutableurlrequest * request = [[nsmutableurlrequest alloc] init]; [Request seturl: [nsurl urlwithstring: urlstring]; [Request sethttpmethod: @ "Post"]; // nsstring * boundary = [nsstring stringwithstring: @ "----------------------- 14737809831466499882746641449"]; nsstring * contenttype = [nsstring stringwithformat: @ "multipart/form-data; boundary = % @", boundary]; [Request addvalue: contenttype forhttpheaderfield: @ "Content-Type"]; // nsmutabledata * Body = [nsmutabledata data]; [Body appenddata: [[nsstring stringwithformat: @ "\ r \ n -- % @ \ r \ n", boundary] datausingencoding: nsutf8stringencoding]; [Body appenddata: [[nsstring stringwithstring: @ "content-Disposition: Form-data; name = \" userfile \"; filename = \ "2.png \" \ r \ n "] datausingencoding: nsutf8stringencoding]; // The Name Of The uploaded image [Body appenddata: [[nsstring stringwithstring: @ "Content-Type: Application/octet-stream \ r \ n"] datausingencoding: nsutf8stringencoding]; [Body appenddata: [nsdata datawithdata: imagedata]; [Body appenddata: [[nsstring stringwithformat: @ "\ r \ n -- % @ -- \ r \ n", boundary] datausingencoding: nsutf8stringencoding]; [Request sethttpbody: body]; // nslog (@ "1-body: % @", body); nslog (@ "2-Request: % @", request); nsdata * returndata = [nsurlconnection sendsynchronousrequest: request returningresponse: Nil error: Nil]; nsstring * returnstring = [[nsstring alloc] initwithdata: returndata encoding: nsutf8stringencoding]; nslog (@ "3-Test output: % @", returnstring );}

2. Image Compression usage: uiimage * yourimage = [self imagewithimagesimple: Image scaledtosize: cgsizemake (210.0, 210.0)];

// Compress the image

- (UIImage*)imageWithImageSimple:(UIImage*)image scaledToSize:(CGSize)newSize{    // Create a graphics image context    UIGraphicsBeginImageContext(newSize);        // Tell the old image to draw in this newcontext, with the desired    // new size    [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];        // Get the new image from the context    UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();        // End the context    UIGraphicsEndImageContext();        // Return the new image.    return newImage;}

3. Attach images to imageview

UIImage *myImage = [UIImage imageNamed:@"1.jpg"];[imageView setImage:myImage];[self.view addSubview:imageView];

4. How to Set navigationbar to hide

self.navigationController.navigationBarHidden = YES;//

5. uilabel multi-Line Text wrap (line breaks)

Uiview * footerview = [[uiview alloc] initwithframe: cgrectmake (10,100,300,180)]; uilabel * label = [[uilabel alloc] initwithframe: cgrectmake (10,100,300,150)]; label. TEXT = @ "Hello world! Hello world! Hello world! Hello world! Hello world! Hello world! Hello world! Hello world! Hello world! Hello world! Hello world! Hello world! Hello world! Helloworld! "; // The background color is red label. backgroundcolor = [uicolor redcolor]; // set the font color to a white label. textcolor = [uicolor whitecolor]; // text center label. textalignment = uitextalignmentcenter; // you can specify a label for automatic line insertion. linebreakmode = uilinebreakmodewordwrap; label. numberoflines = 0;

.............

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.