Iphone development skills

Source: Internet
Author: User

Iphone development skills

1. modify the status bar:

1. Add [[UIApplication sharedApplication] setStatusBarHidden: YES animated: NO]. However, this method only does not display status bars, and the space occupied by status bars still exists.

2. You can modify the Info. plist file, add a new key value to the info. plist file, name it UIStatusBarHidden, select Valuetype as Boolean, and re-compile and run it.

3. Modify the display direction:

[[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationLaNdscapeRight animated: NO];

4. Obtain the project name.

// Obtain the project name and set it to the title of the current view.

Self. title = [[[NSBundle mainBundle] infoDictionary] objectForKey: @ CFBundleName];

5. Set the current view to support touch

SetUserInteractionEnableD: YES;

6. Button. userInteractionEnabled = NO. The Button stops accepting any events.

7. Button. Enabled = NO, the Button is not displayed

8. Get the current mouse position

[NSEvent mouseLocation];

9. Refresh the UITableViewrController View

[Self. TableView reloadData];

10.

Convert string to int

IntegerValue method of NSString

11. Convert the integer to StringWithFormat;

12. Make a simple animation:

-(IBAction) curlAction :( id) sender

{

// Start an animation

[UIView beginAnimations: nil context: NULL];

// Set the animation Interval

[UIView setAnimationDuration: kTransitionDuration];

// Set the animation rotation Mode

[UIView setAnimationTransition :( [self. mainView superview]?

UIViewAnimationTransitioNCurlUp: UIViewAnimationTransitioNCurlDown)

ForView: self. containerView cache: YES];

If ([self. flipToView superview])

{

[Self. flipToView removeFromSuperview];

[Self. containerView addSubview: self. mainView];

}

Else

{

[Self. mainView removeFromSuperview];

[Self. containerView addSubview: self. flipToView];

}

[UIView commitAnimations];

}

13. Use a random number

Use srandom ()

Random (unsigned) (macn_absolute_time () & 0 xFFFFFFFF ));

14. In Quartz, how does one set the rotation point?

UIImageView * imageview = [[UIImageview alloc] initWithImage: [UIImage imageNamed: @bg.png];

ImageView. layer. anchorPoint = CGPointMake (0.5, 1.0 );

15. Hide NavigationBar

[Self. navigationController setNavigationBarHidden: YES animated: YES];

16. Get coordinate (coordinates) based on CLLocation and open google map:

NSString * mapUrl = [NSString stringWithFormat: @ http://maps.google.com/maps? Q = % f, % f, loc. latitude, loc. longpolling];

NSURL * url = [NSURL URLWithString: mapUrl];

[[UIApplication sharedApplication] openURL: url];

17. Date formatting:

NSDataFormat * format = [NSDateFormat alloc]Init];

[Format setDateFormat: @ hh: mm: ss];

NSDate * noew = [NSDate date];

NSString * str = [format stringFromDate: now];

18. WebView usage:

WebView loadRequest: [NSURLRequest alloc] initwithURL: [NSURL alloc] initWithStringt: @ http://www.google.com];

18. Call method through notification:

UIApplication * app = [UIApplication sharedApplication];

[[Nsicationicationcenter defacenter center] addObserve: self

Selector: @ selector (xxx :)

Name: UIApplicationWillTerminaTeNofification

Object: app];

19. How to traverse all views:

The cell is UITableViewCell,

For (UIView * oneView in cell. contentView. subviews)

{

If ([oneView isMemberOfClass: [UITextField class])

{

TextField = (UITextField *) oneView;

}

}

20.

1. Playing background music Supports loop playback of long music in mp3 format

This method of playing music is imported into the framework # import;

NSString * musicFilePath = [[NSBundle mainBundle] pathForResource: @ changan ofType: @ mp3]; // Create a music file path

NSURL * musicURL = [[NSURL alloc] initFileURLWithPath: musicFilePath];

AVAudioPlayer * thePlayer = [[AVAudioPlayer alloc] initWithContentsOfURL: musicURL error: nil];

// Create a player

Self. myBackMusic = thePlayer; // Assign a value to the defined class variable

[MusicURL release];

[ThePlayer release];

[MyBackMusic prepareToPlay];

[MyBackMusic setVolume: 1]; // Set the volume.

MyBackMusic. numberOfLoops =-1; // sets the number of times the music is played. -1 indicates a continuous loop.

If (mainMusicStatus)

{

[MyBackMusic play]; // Play

}

2. Button playing sound Play short sound

Need to import framework # import

NSString * thesoundFilePath = [[NSBundle mainBundle] pathForResource: @ Clapping Crowd Studio 01 ofType: @ caf]; // Create a music file path

CFURLRef thesoundURL = (CFURLRef) [NSURL fileURLWithPath: thesoundFilePath];

AudioServicesCreateSysteMSoundID (thesoundURL, & sameViewSoundID );

// The SoundID variable corresponds to the URL

AudioServicesPlaySystemSOund (sameViewSoundID ); // Play the SoundID sound

21. Set UILabel line feed

UILabel * label;
// Set line feed
Label. lineBreakMode = UILineBreakModeWordWrap;
Label. numberOfLines = 0;
Line break or n
For example, NSString * xstring = @ lineonenlinetwo

 

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.