Develop common functions for IOS

Source: Internet
Author: User

1. Close the keyboard when you click the background.
Add a gesture reader to viewDidLoad.

// add tap gesture recognizer    UITapGestureRecognizer* tapRecognizer = [[UITapGestureRecognizer alloc]                                              initWithTarget:self                                              action:@selector(handleBackgroundTap:)];    tapRecognizer.cancelsTouchesInView = NO;    [self.view addGestureRecognizer:tapRecognizer];

 

Define functions

- (void) handleBackgroundTap:(UITapGestureRecognizer*)sender{    [phoneField resignFirstResponder];    [nameField resignFirstResponder];    [postcodeField resignFirstResponder];    }

In this function, the text field is canceled from the first responder status.

2. Fill the image with the fill color
[UIColor colorWithPatternImage: [UIImage imageNamed: @ "background"];

3. Create and draw a gradient

View Code

 CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();        UIColor *startColor = [UIColor blueColor];    CGFloat *startColorComponents = (CGFloat *)CGColorGetComponents([startColor CGColor]);        UIColor *endColor = [UIColor greenColor];    CGFloat *endColorComponents = (CGFloat *)CGColorGetComponents([endColor CGColor]);        CGFloat colorComponents[8] = {        startColorComponents[0],        startColorComponents[1],        startColorComponents[2],        startColorComponents[3],        endColorComponents[0],        endColorComponents[1],        endColorComponents[2],        endColorComponents[3],    };        CGFloat colorIndices[2] = {        0.0f,        1.0f,    };    CGGradientRef gradient = CGGradientCreateWithColorComponents(colorSpace, (const CGFloat *)&colorComponents, (const CGFloat *)&colorIndices, 2);        CGColorSpaceRelease(colorSpace);        CGRect screenBounds = [[UIScreen mainScreen] bounds];        CGPoint startPoint, endPoint;        CGContextRef context = UIGraphicsGetCurrentContext();    startPoint = CGPointMake(0.0f,screenBounds.size.height/2.0f);    endPoint = CGPointMake(screenBounds.size.width, startPoint.y);    CGContextDrawLinearGradient(context, gradient, startPoint, endPoint, 0);    CGGradientRelease(gradient);

 4. Load the displayed webpage

View Code

NSURL *url = [NSURL URLWithString:_detailItem];    NSURLRequest *request = [NSURLRequest requestWithURL:url];    [_webView loadRequest:request];

5. The navigation bar loads the image as the background


6. Add a shadow to the UIView

View Code

SepLine = [[UIView alloc] init]; sepLine. frame = CGRectMake (LEFT_MARGIN + 5, 0, cellWidth-LEFT_MARGIN-RIGHT_MARGIN, 1); // Add shadow CAGradientLayer * bottomShadow = [[CAGradientLayer alloc] init]; bottomShadow. frame = CGRectMake (2, 0, cellWidth-LEFT_MARGIN-RIGHT_MARGIN + 2, 1); CGColorRef black = [UIColor lightGrayColor]. CGColor; CGColorRef white = [UIColor whiteColor]. CGColor; bottomShadow. colors = [NSArray arrayWithObjects :( _ bridge id) black, (_ bridge id) white, nil]; [sepLine. layer addSublayer: bottomShadow];

7 synchronous synchronization for iOS
Use NSLock and @ synchronized to protect critical zones
You can also use dispatch_sync

8. Obtain screen information
UIScreen is used to obtain the screen objects of all current screens (including the device's main screen. The screen object contains the screen property information (including the size and
Pixel ratio also takes into account the screen features ).

9 Asset Library Framework
IOS 4.0 introduces the Asset Library framework (AssetsLibrary. framework), which provides a query interface through which you can search for user photos and data. By using this framework, you can access the assets managed by Photos, including the albums saved by users and images or videos imported to devices. You can also save photos or videos to your album.

 

 

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.